Created
August 24, 2021 12:06
-
-
Save kubido/6ecc3d708ce6e7994269060311785540 to your computer and use it in GitHub Desktop.
halodoc hospitals scrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('Faraday') | |
require('json') | |
def fetch_hospitals(page=1) | |
url = "https://www.halodoc.com/api/rumah-sakit/v1/hospitals/search" | |
params = { page_no: page, per_page: 20 }.to_json | |
headers = { "Content-Type": "application/json"} | |
response = Faraday.put(url, params, headers) | |
return JSON.parse(response.body) | |
end | |
current_page = 1 | |
end_page = false | |
while !end_page | |
data = fetch_hospitals(current_page) | |
current_page += 1 | |
puts current_page | |
end_page = data['next_page'] == "false" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment