forked from TheAlgorithms/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqimai_data.py
93 lines (78 loc) · 3.18 KB
/
qimai_data.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
"""
Qimai Data (qimai.cn) is a mobile product business analysis platform in China.
Get a dict of the app information for a given typename (free, paid, grossing) from https://www.qimai.cn
p.s. Current version of DrissionPage : 4.0.4.17
https://github.com/g1879/DrissionPage
"""
from DrissionPage import ChromiumPage
def login(page: ChromiumPage, username: str, password: str) -> bool:
page.get("https://www.qimai.cn/account/signin/r/%2F")
if page.url != "https://www.qimai.cn/":
try:
page.ele("@name=username").input(username)
page.ele("@name=password").input(password)
page.ele(".submit").click()
print("Login successfully")
return True
except KeyError:
print("Login failed")
page.close()
return False
else:
print("Already login")
return True
def get_app_info(
page: ChromiumPage, username: str, password: str, typename: str
) -> dict:
# Clear the cache to avoid the login failure
page.clear_cache(cookies=True)
if login(page, username, password):
# Get the data of default page
page.listen.start(f"brand={typename}&device=iphone&country=cn&genre=5000")
page.get(
f"https://www.qimai.cn/rank/index/brand/{typename}/device/iphone/country/cn/genre/5000"
)
# Get the response data
res = page.listen.wait().response.body
dic = {}
for i in range(len(res["rankInfo"])):
font = res["rankInfo"][i]["appInfo"]
dic[font["appId"]] = {
"appId": font["appId"],
"appName": font["appName"],
"country": font["country"],
"file_size": font["file_size"],
"icon_path": font["icon"],
"price": font["price"],
"publisher": font["publisher"],
"subtitle": font["subtitle"],
}
# Get the data of other pages
if res["maxPage"] > 1:
for page_num in range(1, res["maxPage"]):
# Target the page number
page.listen.start(f"page={page_num + 1}")
print(f"Getting page {page_num + 1}")
# Chrome will scroll to the bottom of the page to load more data
page.scroll.to_bottom()
page.wait.load_start()
res = page.listen.wait().response.body
for i in range(len(res["rankInfo"])):
font = res["rankInfo"][i]["appInfo"]
dic[font["appId"]] = {
"appId": font["appId"],
"appName": font["appName"],
"country": font["country"],
"file_size": font["file_size"],
"icon_path": font["icon"],
"price": font["price"],
"publisher": font["publisher"],
"subtitle": font["subtitle"],
}
else:
return {"error": "Login failed"}
return dic
if __name__ == "__main__":
page = ChromiumPage()
print(get_app_info(page, "YOUR USERNAME", "YOUR PASSWORD", "free"))
page.close()