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 ()
0 commit comments