-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
68 lines (53 loc) · 1.89 KB
/
main.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import requests
import json
import xlsxwriter
import time
# Workbook() takes one, non-optional, argument
# which is the filename that we want to create.
workbook = xlsxwriter.Workbook('reviews.xlsx')
# The workbook object is then used to add new
# worksheet via the add_worksheet() method.
worksheet = workbook.add_worksheet()
worksheet.write('A1', 'Name')
worksheet.write('B1', 'Date')
worksheet.write('C1', 'Description')
worksheet.write('D1', 'Stars')
urlNumber = 0
cellIndex = 2
try:
while(True):
url = 'https://www.google.com/maps/preview/review/listentitiesreviews?authuser=0&hl=en&gl=in&pb=!1m2!1y4111766323478979231!2y1273414400129857113!2m2!1i' + \
str(urlNumber) + \
'0!2i10!3e1!4m5!3b1!4b1!5b1!6b1!7b1!5m2!1sRNybYaCrIaSq4t4Pi-2KgAE!7e81'
r = requests.get(url)
data = r.content.decode('utf-8')
myData = data.split(")]}'")[1].strip()
res = json.loads(myData)
if res[2] == None:
break
if urlNumber > 10:
break
reviews = res[2]
worksheet.write('E'+str(cellIndex), len(reviews))
for review in reviews:
# print('date:')
# print(review[1])
# print('desc:')
# print(review[3])
# print('rating:')
# print(review[4])
# print('\n\n')
worksheet.write('A'+str(cellIndex), review[0][1])
worksheet.write('B'+str(cellIndex), review[1])
worksheet.write('C'+str(cellIndex), review[3])
worksheet.write('D'+str(cellIndex), review[4])
cellIndex = cellIndex+1
urlNumber = urlNumber + 1
time.sleep(0)
except:
print('An error has occured (google might have blocked your IP, you may have virus 😂)')
print('Last urlNumber', urlNumber)
finally:
# Finally, close the Excel file
# via the close() method.
workbook.close()