Sitemap
Rwand

Rwand

Learn to Share

How to Scrap API Using Python

2 min readJul 14, 2020
Press enter or click to view image in full size

Let’s scrap API using Python, we will scrap Float Rates website for Indonesia Rate Currency.

Get Rwand’s stories in your inbox

Join Medium for free to get updates from this writer.

What we will use:

  • Python Language
  • Flask
  • Jinja Templates
  • Bootstrap Templates

Project Structure

idr_rate_scraper.py

In this file, we create a module to get JSON data from Float Rates website.

import requestsdef getRates(url):  json_data = requests.get(url)  return json_data.json().values()

Here we use request python library and we use get method to fetch the URL. After we get the response, we return the JSON value.

run.py

In this file, we create a route to render the HTML.

from flask import Flask, render_templatefrom idr_rate_scraper import getRates
app = Flask(__name__)@app.route('/')def home(): return render_template('index.html')@app.route('/idr-rates')def idr_rates(): url = 'http://www.floatrates.com/daily/idr.json' data_json = getRates(url) return render_template('index.html', data=data_json)if __name__ == "__main__": app.run(debug=True)

Here we import getRates module from idr_rate_scraper file that we have created before. And run the module on route idr-rates.

index.html

Here we create an Html table to show the result what we got before.

Result

And this the result of what we have done.

Press enter or click to view image in full size

--

--