-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgoogleplay.py
325 lines (245 loc) · 8.18 KB
/
googleplay.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/usr/bin/env python
from bs4 import BeautifulSoup
import sys
import urllib
import urllib2
import json
package = ""
#Entry point
def searchApp (pack):
global package
package = pack
#Creates the soup
def createSoup():
global package
url = "https://play.google.com/store/apps/details?id=" + package
try:
response = urllib.urlopen( url )
except urllib.error.HTTPError as e:
print( "HTTPError with: ", url, "\t", e )
return None
the_page = response.read()
soup = BeautifulSoup( the_page )
return soup
#Returns the App title
def getAppTitle(display):
soup = createSoup()
title_div = soup.find( 'div', {'class':'document-title'} )
title = title_div.find( 'div' ).get_text().strip()
if display:
print title
return title
#Returns the developer name
def getAppDeveloper(display):
global package
soup = createSoup()
subtitle = soup.find( 'a', {'class' : 'document-subtitle primary'} )
developer = subtitle.get_text().strip()
dev_link = subtitle.get('href').strip()
if display:
print developer
return developer
#Returns the dev link
def getAppDevLink(display):
global package
soup = createSoup()
subtitle = soup.find( 'a', {'class' : 'document-subtitle primary'} )
developer = subtitle.get_text().strip()
dev_link = subtitle.get('href').strip()
if display:
print dev_link
return dev_link
#Returns the App updated date
def getAppUpdateDate(display):
global package
soup = createSoup()
date_published = soup.find( 'div', {'itemprop' : 'datePublished'} )
updated = date_published.get_text().strip()
if display:
print updated
return updated
#Returns the category
def getAppCategory(display):
global package
soup = createSoup()
category_get = soup.find( 'span', {'itemprop' : 'genre'} )
category = category_get.get_text()
if display:
print category
return category
#Returns the rating
def getAppRating(display):
global package
soup = createSoup()
rating_value = soup.find( 'meta', {'itemprop' : 'ratingValue'} )
rating = rating_value.get( 'content' ).strip()
if display:
print rating
return rating
#Returns reviewers count
def getAppReviewersCount(display):
global package
soup = createSoup()
reviewers_count = soup.find( 'meta', {'itemprop' : 'ratingCount'} )
reviewers = reviewers_count.get( 'content' ).strip()
if display:
print reviewers
return reviewers
#Returns the app badge
def getAppBadge(display):
global package
soup = createSoup()
has_badge = soup.find( 'span', {'class' : 'badge-title'} )
if has_badge:
badge = has_badge.get_text().strip()
if display:
print badge
return badge
#Returns the description of the app
def getAppDesc(display):
global package
soup = createSoup()
desc = []
description_div = soup.find_all( 'div', {'class':'id-app-orig-desc'} )
for descs in description_div:
desc.append(descs.get_text().strip())
if display:
for log in desc:
print log
return desc
#Returns the app reviews
def getAppReviews(display):
global package
reviews = []
i = -1
cur = 0
while True:
i += 1
url = "https://play.google.com/store/getreviews"
data = "reviewType=0&pageNum=" + str(i) + "&id=" + package + "&reviewSortOrder=4&xhr=1"
headers = { "orgin" : "https://play.google.com",
"accept-language": "en-US,en;q=0.8",
"user-agent": "Mozilla/5.0 (X1; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36",
"content-type": "application/x-www-form-urlencoded;charset=UTF-8",
"accept": "*/*",
"referer": "https://play.google.com/store/apps/details?id="+package}
req = urllib2.Request(url, data, headers)
response = urllib2.urlopen(req)
the_page = response.read()[6:]
js = json.loads(the_page)
try:
page = js[0][2]
if not page:
raise IndexError
soup = BeautifulSoup( page )
except IndexError:
break
if not soup: return None
reviews_div = soup.find_all( 'div', {'class':'single-review'} )
for review in reviews_div:
cur += 1
if display:
print str(cur)+')', review.find(class_='author-name').get_text().strip(), review.find(class_='tiny-star').get('aria-label').strip(), 'On', review.find(class_='review-date').get_text().strip()
body = review.find(class_='review-body')
title = body.find(class_='review-title')
link = body.find(class_='review-link')
text = title.get_text().strip()
if display:
print 'TITLE:', text and text or '(no title)'
title.decompose()
link.decompose()
text = body.get_text().strip()
reviews.append(text)
if display:
print 'REVIEW:', text and text or '(no content)'
print
if cur % 20 != 0:
break
print 'TOTAL REVIEWS:', cur
return reviews
#Returns the What's new
def getAppUpdate(display):
global package
soup = createSoup()
change = []
changes_div = soup.find_all( 'div', {'class':'recent-change'} )
for changes in changes_div:
change.append(changes.get_text().strip())
if display:
for log in change:
print log
return change
#ADDITIONAL INFORMATION
#Returns the size
def getAppSize(display):
global package
soup = createSoup()
app_size = soup.find( 'div', {'itemprop' : 'fileSize'} )
size = app_size.get_text().strip()
if display:
print size
return size
#Returns the number of installs
def getAppInstalls(display):
global package
soup = createSoup()
num_downloads = soup.find( 'div', {'itemprop' : 'numDownloads'} )
if num_downloads:
numDownloads = num_downloads.get_text().strip()
if display:
print numDownloads
return numDownloads
#Returns the App OS
def getAppOS(display):
global package
soup = createSoup()
operating_systems = soup.find( 'div', {'itemprop' : 'operatingSystems'} )
os = operating_systems.get_text().strip()
if display:
print os
return os
#Returns the maturity content of the app
def getAppMaturity(display):
global package
soup = createSoup()
content_rating = soup.find( 'div', {'itemprop' : 'contentRating'} )
content = content_rating.get_text().strip()
if display:
print content
return content
#Returns the developer links
def getAppDevLinks(display):
global package
soup = createSoup()
links = []
for dev_link in soup.find_all( 'a', {'class' : 'dev-link'} ):
if dev_link.get_text().strip() == "Email Developer":
email = dev_link.get( 'href' ).strip()[7:]
links.append(email)
elif dev_link.get_text().strip() == "Visit Developer's Website":
dev_website = dev_link.get( 'href' ).strip()
links.append(dev_website)
if display:
for link in links:
print link
return links
def getAppPermissions(display):
global package
soup = createSoup()
permission = []
perms = soup.find_all( 'div', {'class':'permissions-heading'} )
print perms
for perm in perms:
permission.append(perm.get_text().strip())
print "hie"
if display:
for log in permission:
print log
return permission
if __name__ == '__main__':
args = sys.argv[1:]
if not args:
print >> sys.stderr, 'SYNTAX: googleplay.py [app-package-name]'
sys.exit(-1)
searchApp(args[0])
getAppCategory(1)