-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scraping_reviews.py
46 lines (41 loc) · 1.32 KB
/
Scraping_reviews.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from bs4 import BeautifulSoup
import requests
import json
list=[]
url = 'https://www.e-food.gr/delivery/ilion/gyradiko-o-daskalos#pills-ratings'
res = requests.get(url)
soup = BeautifulSoup(res.text, features="lxml")
text = res.text
userIdText = 'app.userSid = '
pos = text.find(userIdText)
start = pos + len(userIdText)
userId = text[start:start + 34]
#print(userId)
restText = 'var restaurant_id = '
pos = text.find(restText)
start = pos + len(restText)
restId = text[start:start + 7]
#print(restId)
limit = soup.find("a", {"id": "ratings-tab"})
print(limit.text)
start = limit.text.find('(') + 1
end = limit.text.find(')')
limit = limit.text[start:end]
#print(limit)
headers = {"X-core-session-id": userId,
"Accept-Language": 'el',
"X-core-platform": 'web',
"X-core-version": '3'
}
url = 'https://api.e-food.gr/api/v1/restaurants/' + restId + '/ratings/?limit=' + limit
response = requests.get(url, headers=headers) # modify request headers
#print(response.headers) # print response headers
#print(response.headers['Content-Type'])
#print(response.text)
resp = json.loads(response.text)
#print(resp['data'])
for comm in resp['data']:
if comm['comment']:
list.append(comm['comment'])
for review in list:
print ("Review:", review)