Skip to content

Commit 7d28879

Browse files
Merge pull request #2199 from Mihan786Chistie/eazydiner
Eazydiner Restaurant Scrapper added
2 parents 2be9be3 + 5091036 commit 7d28879

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

EazyDiner-Scraper/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## EazyDiner
2+
3+
### Scrape restaurants name, location, rating, cuisine and prices from eazydiner website for a given city
4+
5+
Create an instance of `EazyDiner` class.
6+
7+
```python
8+
restaurants = EazyDiner(location="city-name")
9+
```
10+
11+
| Methods | Details |
12+
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
13+
| `.getRestaurants()` | Returns the restaurants name, location, rating, cuisine and prices in JSON format. Check the cities which are accepted in the [eazydiner](https://www.eazydiner.com/) website |
14+
15+
```

EazyDiner-Scraper/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
json
2+
requests
3+
beautifulsoup4

EazyDiner-Scraper/restaurants.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import json
2+
import requests
3+
from bs4 import BeautifulSoup
4+
5+
6+
class EazyDiner:
7+
"""
8+
Class - `EazyDiner`
9+
Example:
10+
```
11+
restaurants = EazyDiner(location="Delhi NCR")
12+
```
13+
Methods :
14+
1. ``.getRestaurants() | Response - List of restraunts and its details.
15+
"""
16+
17+
def __init__(self, location):
18+
self.location = location
19+
20+
def getRestaurants(self):
21+
"""
22+
Class - `EazyDiner`
23+
Example:
24+
```
25+
del = EazyDiner("Delhi NCR") or del = EazyDiner("delhi-ncr")
26+
del.getRestaurants()
27+
```
28+
Returns:
29+
{
30+
"restaurant": restaurant name
31+
"location": location of restaurant
32+
"rating": rating
33+
"cuisine": cuisines provided
34+
"price": price for two people
35+
}
36+
"""
37+
url = (
38+
"https://www.eazydiner.com/restaurants?location="
39+
+ self.location.replace(" ", "-").replace(",", "").lower()
40+
)
41+
try:
42+
res = requests.get(url)
43+
soup = BeautifulSoup(res.text, "html.parser")
44+
45+
restaurant_data = {"restaurants": []}
46+
47+
restaurants = soup.select(".restaurant")
48+
for r in restaurants:
49+
name = r.find("h3", class_="res_name").getText().strip()
50+
location = r.find("h3", class_="res_loc").getText().strip()
51+
rating = r.find("span", class_="critic").getText().strip()
52+
cuisine = (
53+
r.find("div", class_="res_cuisine").getText().replace(",", ", ")
54+
)
55+
price = (
56+
r.find("span", class_="cost_for_two")
57+
.getText()
58+
.encode("ascii", "ignore")
59+
.decode()
60+
.strip()
61+
)
62+
restaurant_data["restaurants"].append(
63+
{
64+
"restaurant": name,
65+
"location": location,
66+
"rating": rating,
67+
"cuisine": cuisine,
68+
"price": "Rs. " + price + " for two",
69+
}
70+
)
71+
res_json = json.dumps(restaurant_data)
72+
return res_json
73+
except ValueError:
74+
return None

0 commit comments

Comments
 (0)