Skip to content

Commit 3684df1

Browse files
added EazyDiner class and getRestaurants() function
1 parent 53773bd commit 3684df1

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

EazyDiner-Scraper/restaurants.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import json
2+
import requests
3+
from bs4 import BeautifulSoup
4+
5+
6+
class EazyDiner:
7+
8+
9+
def __init__(self, location):
10+
self.location = location
11+
12+
def getRestaurants(self):
13+
14+
url = (
15+
"https://www.eazydiner.com/restaurants?location="
16+
+ self.location.replace(" ", "-").replace(",", "").lower()
17+
)
18+
try:
19+
res = requests.get(url)
20+
soup = BeautifulSoup(res.text, "html.parser")
21+
22+
restaurant_data = {"restaurants": []}
23+
24+
restaurants = soup.select(".restaurant")
25+
for r in restaurants:
26+
name = r.find("h3", class_="res_name").getText().strip()
27+
location = r.find("h3", class_="res_loc").getText().strip()
28+
rating = r.find("span", class_="critic").getText().strip()
29+
cuisine = (
30+
r.find("div", class_="res_cuisine").getText().replace(",", ", ")
31+
)
32+
price = (
33+
r.find("span", class_="cost_for_two")
34+
.getText()
35+
.encode("ascii", "ignore")
36+
.decode()
37+
.strip()
38+
)
39+
restaurant_data["restaurants"].append(
40+
{
41+
"restaurant": name,
42+
"location": location,
43+
"rating": rating,
44+
"cuisine": cuisine,
45+
"price": "Rs. " + price + " for two",
46+
}
47+
)
48+
res_json = json.dumps(restaurant_data)
49+
return res_json
50+
except:
51+
return None
52+
53+

0 commit comments

Comments
 (0)