Skip to content

To get Qimai data #11338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
beautifulsoup4
DrissionPage ; python_version > '4.0.4.12'
fake_useragent
imageio
keras ; python_version < '3.12'
Expand Down
93 changes: 93 additions & 0 deletions web_programming/qimai_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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()
Loading