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
# Import Libraries | |
import requests | |
import json | |
import datetime | |
import pandas as pd | |
# Define Parameters Dictionary | |
params = dict() | |
params['access_token'] = 'XXXXXXXXXXXXXXXXXXX' # not an actual access token | |
params['client_id'] = '111111111111' # not an actual client id |
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
#Restaurant Latitude and Longitude | |
map_url = driver.find_element_by_xpath("""/html/body/div[1]/div[2]/main/div/section[4]/section/article/section/div[2]/a""").get_attribute("href") | |
lat = map_url[-28:-15] | |
long = map_url[-14:-1] | |
rest_lat.append(lat) | |
rest_long.append(long) | |
print(f'Scraping Restaurant Latitude-Longitude - {name} - {lat} - {long} - OK') |
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
#Restaurant Additional Information | |
addt_info_list = [] | |
addt_info_bigelt = driver.find_element_by_xpath("""/html/body/div[1]/div[2]/main/div/section[4]/section/section/article[1]/section[2]/div[3]""") | |
addt_info_eltlist = addt_info_bigelt.find_elements_by_tag_name('p') | |
for addt_info_anchor in addt_info_eltlist: | |
addt_info_text = addt_info_anchor.text | |
addt_info_list.append(addt_info_text) | |
rest_info.append(addt_info_list) |
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
#Restaurant Price for 2 | |
try: | |
price_for_2_anchor = driver.find_element_by_xpath("""/html/body/div[1]/div[2]/main/div/section[4]/section/section/article[1]/section[2]/p[1]""") | |
price_for_2_text = price_for_2_anchor.text | |
except NoSuchElementException: | |
price_for_2_text = "No Price Data Found" | |
pass | |
if (price_for_2_text[0:2] == 'Rp') or (price_for_2_text[0:2] == 'No'): |
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
#Restaurant Rating | |
try: | |
rest_rating_anchor = driver.find_element_by_xpath("""/html/body/div[1]/div[2]/main/div/section[3]/section/section[2]/section/div[1]/p""") | |
rest_rating_text = rest_rating_anchor.text | |
except NoSuchElementException: | |
rest_rating_text = "Not Rated Yet" | |
pass | |
rest_rating.append(rest_rating_text) | |
print(f'Scraping Restaurant Area - {name} - {rest_rating_text} - OK') |
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
#Restaurant Area | |
rest_area_anchor = driver.find_element_by_xpath("""/html/body/div[1]/div[2]/main/div/section[3]/section/section[1]/section[1]/a""") | |
rest_area_text = rest_area_anchor.text | |
rest_area.append(rest_area_text) | |
print(f'Scraping Restaurant Area - {name} - {rest_area_text} - OK') | |
#Restaurant Address | |
rest_address_anchor = driver.find_element_by_xpath("""/html/body/div[1]/div[2]/main/div/section[4]/section/article/section/p""") | |
rest_address_text = rest_address_anchor.text | |
rest_address.append(rest_address_text) |
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
#Restaurant Type | |
rest_type_list = [] | |
rest_type_eltlist = driver.find_elements_by_xpath("""/html/body/div[1]/div[2]/main/div/section[3]/section/section[1]/section[1]/div/a""") | |
for rest_type_anchor in rest_type_eltlist: | |
rest_type_text = rest_type_anchor.text | |
rest_type_list.append(rest_type_text) | |
rest_type.append(rest_type_list) | |
print(f'Scraping Restaurant Type - {name} - {rest_type_text} - OK') |
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
# Initialize Empty List that we will use to store the scraping data results | |
rest_name = [] | |
driver = webdriver.Chrome(chromepath) | |
# Scrape the data by looping through entries in DataFrame | |
for url in out_df_nd['Website']: | |
driver.get(url) | |
print('Accessing Webpage OK') |
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
# Initialize Empty Lists that we will use to store the scraping data results | |
rest_name = [] | |
driver = webdriver.Chrome(chromepath) | |
# Scrape the data by looping through entries in DataFrame | |
for url in out_df_nd['Website']: | |
driver.get(url) | |
name_anchor = driver.find_element_by_tag_name('h1') | |
name = name_anchor.text |
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
# Set Webdriver | |
driver = webdriver.Chrome(chromepath) | |
out_lst_dlv = [] | |
# Loop Through - Search Pages that we wanted | |
for i in range(1, 224): | |
print('Opening Search Pages ' + str(i)) | |
driver.get('https://www.zomato.com/jakarta/delivery?page={}'.format(i)) | |
print('Accessing Webpage OK \n') | |
url_elt_dlv = driver.find_elements_by_class_name("result-title") |