我正在做一个python项目,在那里我需要找出公司拥有的应用程序。例如,我有一个列表:
company_name = ['Airbnb', 'WeFi']我想编写一个python函数/程序来完成以下工作:
1.让它自动在播放存储中的列表中的搜索项
2.如果公司名称匹配,即使它只匹配名称,如"Airbnb“将匹配"Airbnb,inc.”


tuple = {app name, category}中。例:
print(company_name[0])
print(type(company_name[0]))结果:
爱彼迎
元组
print(company_name[0][0])结果:
(“airbnb”、“旅行”)
这是许多知识的混合体,我是蟒蛇的新手。所以,请给我一些指导,我应该如何开始写代码。
我知道selenium可以自动实现“加载更多”功能,但我不确定我到底可以使用什么包?
发布于 2016-08-23 23:46:33
我已经写了一个小演示,可以帮助你实现你的目标。我用的是请求和美丽的汤。这并不完全是你想要的,但它可以很容易地适应。
import requests
import bs4
company_name = "airbnb"
def get_company(company_name):
r = requests.get("https://play.google.com/store/search?q="+company_name)
soup = bs4.BeautifulSoup(r.text, "html.parser")
subtitles = soup.findAll("a", {'class':"subtitle"})
dev_urls = []
for title in subtitles:
try:
text = title.attrs["title"].lower()
#Sometimes there is a subtitle without any text on GPlay
#Catchs the error
except KeyError:
continue
if company_name in text:
url = "https://play.google.com" + title.attrs["href"]
dev_urls.append(url)
return dev_urls
def get_company_apps_url(dev_url):
r = requests.get(dev_url)
soup = bs4.BeautifulSoup(r.text, "html.parser")
titles = soup.findAll("a", {"class":"title"})
return ["https://play.google.com"+title.attrs["href"] for title in titles]
def get_app_category(app_url):
r = requests.get(app_url)
soup = bs4.BeautifulSoup(r.text, "html.parser")
developer_name = soup.find("span", {"itemprop":"name"}).text
app_name = soup.find("div", {"class":"id-app-title"}).text
category = soup.find("span", {"itemprop":"genre"}).text
return (developer_name, app_name, category)
dev_urls = get_company("airbnb")
apps_urls = get_company_apps_url(dev_urls[0])
get_app_category(apps_urls[0])
>>> get_company("airbnb")
['https://play.google.com/store/apps/developer?id=Airbnb,+Inc']
>>> get_company_apps_url("https://play.google.com/store/apps/developer?id=Airbnb,+Inc")
['https://play.google.com/store/apps/details?id=com.airbnb.android']
>>> get_app_category("https://play.google.com/store/apps/details?id=com.airbnb.android")
('Airbnb, Inc', 'Airbnb', 'Travel & Local')我在谷歌的剧本
dev_urls = get_company("google")
apps_urls = get_company_apps_url(dev_urls[0])
for app in apps_urls:
print(get_app_category(app))
('Google Inc.', 'Google Duo', 'Communication')
('Google Inc.', 'Google Translate', 'Tools')
('Google Inc.', 'Google Photos', 'Photography')
('Google Inc.', 'Google Earth', 'Travel & Local')
('Google Inc.', 'Google Play Games', 'Entertainment')
('Google Inc.', 'Google Calendar', 'Productivity')
('Google Inc.', 'YouTube', 'Media & Video')
('Google Inc.', 'Chrome Browser - Google', 'Communication')
('Google Inc.', 'Google Cast', 'Tools')
('Google Inc.', 'Google Sheets', 'Productivity')发布于 2018-12-06 04:52:26
下面是另一个以编程方式搜索google的选项:
https://github.com/facundoolano/google-play-scraper/#list
var gplay = require('google-play-scraper');
gplay.list({
category: gplay.category.GAME_ACTION,
collection: gplay.collection.TOP_FREE,
num: 2
})
.then(console.log, console.log);(它是nodejs,而不是python )
https://stackoverflow.com/questions/39111251
复制相似问题