-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrape_app.py
executable file
·75 lines (38 loc) · 1.34 KB
/
scrape_app.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
#!/usr/bin/env python3
# scrape_app.py - Takes app name and provides age, overall ranking, global rank ,
# description and screenshots of that app.
# import modules
import requests, webbrowser, bs4, sys, json
# import App class
from app_class import App
#Takes app name as argument dynamically from user
app_name = ' '.join(sys.argv[1: ])
# app_name = 'Minecraft' chekcing
#Requests for app page
res = requests.get("https://www.apptrace.com/app?query=" + app_name)
try:
res.raise_for_status()
except Exception as exc:
print("ERROR!")
#Beautiful soup object
soup = bs4.BeautifulSoup(res.text, 'html.parser')
#Check if matching app found and then scrapes out the redirected link
linkElem = soup.select_one('div .link a')
if linkElem:
linkElemhref = soup.select_one('div .link a').get('href')
else:
print("Sorry, there are no Apps matching your search criteria")
# Searches for app asked by user and download the page.
res = requests.get('https://www.apptrace.com' + linkElemhref)
try:
res.raise_for_status()
except Exception as exc:
print("ERROR!")
# Converts into Beautiful object
content = bs4.BeautifulSoup(res.text, 'html.parser')
# Scrapes information about required parameters.
app = App(content)
#Converts to json format
jsonStr = json.dumps(app.__dict__)
#Outputs to console
print(jsonStr)