lobitrip.blogg.se

Restaurants around me
Restaurants around me






  1. RESTAURANTS AROUND ME HOW TO
  2. RESTAURANTS AROUND ME CODE

If there are 58, then it would be three pages. Let’s say there are 40 restaurants around Sanur, then Google will show the data in two pages. Since Google only shows 20 points of data in each page, we have to insert ‘next_page_token’ to scrape the next page’s data.

RESTAURANTS AROUND ME CODE

The code allows us to get the place’s name, id, latitude-longitude, rating, type, and vicinity for every coordinate and keyword. for coordinate in coordinates: for keyword in keywords: url = ''+coordinate+'&radius='+str(radius)+'&keyword='+str(keyword)+'&key='+str(api_key) while True: print(url) respon = requests.get(url) jj = json.loads(respon.text) results = jj for result in results: name = result place_id = result lat = result lng = result rating = result types = result vicinity = result data = final_data.append(data) time.sleep(5) if 'next_page_token' not in jj: break else: next_page_token = jj url = ''+str(api_key)+'&pagetoken='+str(next_page_token) labels = Third step: Craft a code that generates data based on your parameters in step 1. Second step: Prepare some libraries needed, such as: import pandas as pd, numpy as np import requests import json import time from lab import filesĭid you notice the “from lab import files”? Yes, using Google Colab requires us to use lab library to open or save data. However, the downside of using ‘keywords’ is it will take a longer time to clean the data. If we use ‘type’, we’ll only get places whose type is ‘restaurant’. If we use ‘name’, we’ll only get places whose name has ‘restaurant’ in it. For example, I can get Sushi Tei and Se’i Sapi Restaurant at the same time. So, I think it’s better compared to using ‘name’ or ‘type’ of places because I can get complete list of places that the type and the name contain ‘restaurant’.

restaurants around me

The ‘keywords’ let us get any places that are registered as restaurants OR whose name has ‘restaurant’ in it. Translated into Python, it would be: coordinates = keywords = radius = '1000' api_key = 'acbhsjbfeur2y8r' #insert your API key here So, the parameters would be ‘restaurant’, ‘Sanur Beach’ (in coordinate), and ‘1 km’. The first step: What data would you like to get?įor me, I would like to get restaurants around me (chilling by the beach in Sanur, Bali) in radius of 1 km. So, I could get the complete list of restaurants around me, with its address & ratings, in a simple spreadsheet! Sounds great, I think. The output is usually in form of spreadsheet. Data scraping, or web scraping, is importing data from website into our local machine. The answer is - of course - data scraping.

RESTAURANTS AROUND ME HOW TO

Finding out how to make that “if only….” real. Once I came back from the vacay, I rushed to my laptop. “If only I had the complete list of all restaurants nearby with its rating and address…” said the little voice in my head. We all know Bali for its Ayam Betutu, Sate Lilit, and Lawar - yet I didn’t know where to get them, or to be exact, I didn’t know what places are best to get them. As a foodie I am, food is the first thing I was thinking of when I arrived.

restaurants around me

It was on peak season - of course, wrong choice of time. This is what I experienced when I went to Bali last December. I have always been that person who reaches for my smartphone once a question struck my mind faster when it relates to food. Foods Around Me: Google Maps Data Scraping with Python & Google Colab








Restaurants around me