Skip to content

Commit 6bceedc

Browse files
Merge pull request avinashkranjan#2206 from Swapnil-Singh-99/Zomato_Scapper
Added Zomato Menu Scrapper
2 parents 2d9677a + 993c7f7 commit 6bceedc

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

Zomato Data Scraper/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Zomato Data Scrapper
2+
It is a zomato item scrapping python script that will scrape the items from the restraunt's page and display to the user on the terminal
3+
4+
# Installation & Run
5+
`pip install -r requirements.txt`
6+
7+
`python main.py`
8+
9+
# Screenshots
10+
![image.png](https://i.postimg.cc/G232VD3g/image.png)

Zomato Data Scraper/main.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Imports
2+
# for soup find
3+
from bs4 import BeautifulSoup as bs
4+
# uses a automated web browser for automations
5+
from selenium import webdriver
6+
from selenium.webdriver.chrome.options import Options
7+
from selenium.webdriver.chrome.service import Service
8+
from selenium.webdriver.common.by import By
9+
from webdriver_manager.chrome import ChromeDriverManager
10+
11+
12+
# Chrome options for selenium server
13+
chrome_options = webdriver.ChromeOptions()
14+
chrome_options.add_argument("--headless")
15+
chrome_options.add_argument("--disable-dev-shm-usage")
16+
chrome_options.add_argument("--no-sandbox")
17+
18+
def get_Zomato_menu(zlink):
19+
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
20+
driver.get(zlink)
21+
current_zomato_data = {}
22+
for i in range(2,20):
23+
try:
24+
category_name = driver.find_element(by=By.XPATH, value=f"/html/body/div[1]/div/main/div/section[4]/section/section[2]/section[{i}]/h4").get_attribute("innerHTML")
25+
if category_name != "" and category_name != "Recommended":
26+
items = []
27+
for j in range(1,25):
28+
try:
29+
item_name = driver.find_element(by=By.XPATH, value=f"/html/body/div[1]/div/main/div/section[4]/section/section[2]/section[{i}]/div[2]/div[{j}]/div/div/div[2]/div/div/h4").get_attribute("innerHTML")
30+
try:
31+
item_price = driver.find_element(by=By.XPATH, value=f"/html/body/div[1]/div/main/div/section[4]/section/section[2]/section[{i}]/div[2]/div[{j}]/div/div/div[2]/div/div/div[2]/span").get_attribute("innerHTML")
32+
except:
33+
item_price = driver.find_element(by=By.XPATH, value=f"/html/body/div[1]/div/main/div/section[4]/section/section[2]/section[{i}]/div[2]/div[{j}]/div/div/div[2]/div/div/div/span").get_attribute("innerHTML")
34+
item_price = item_price[1:]
35+
listing = [item_name, item_price]
36+
items.append(listing)
37+
except:
38+
pass
39+
category_name_data = {}
40+
for i in items:
41+
item_name = i[0]
42+
item_price = i[1]
43+
category_name_data[item_name] = item_price
44+
current_zomato_data[category_name] = category_name_data
45+
except:
46+
pass
47+
return current_zomato_data
48+
49+
print()
50+
51+
if __name__ == "__main__":
52+
print("Enter the URL of Zomato's restraunt: ")
53+
zlink = str(input())
54+
data = get_Zomato_menu(zlink)
55+
for i in data:
56+
category_name = i
57+
print("## ", category_name)
58+
print()
59+
items = data.get(i)
60+
for j in items:
61+
print(j, " : ", items.get(j))
62+
print()

Zomato Data Scraper/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
beautifulsoup4==4.11.1
2+
selenium==4.10.0
3+
webdriver_manager==3.8.6

0 commit comments

Comments
 (0)