我从Python和Beautiful Soup开始,将googleplaystore和应用程序元数据放到JSON文件中。这是我的密码:
def createjson(app_link):
url = 'https://play.google.com/store/apps/details?id=' + app_link
response = get(url)
html_soup = BeautifulSoup(response.text, 'html.parser')
bs = BeautifulSoup(response.text,"lxml")
result = [e.text for e in bs.find_all("div",{"class":"hAyfc"})]
apptype = [e.text for e in bs.find_all("div",{"class":"hrTbp R8zArc"})]
data = {}
data['appdata'] = []
data['appdata'].append({
'name': html_soup.find(class_="AHFaub").text,
'updated': result[1][7:],
'apkSize': result[2][4:],
'offeredBy': result[9][10:],
'currentVersion': result[4][15:]
})
jsonfile = "allappsdata.json" #Get all the appS infos in one JSON
with open(jsonfile, 'a+') as outfile:
json.dump(data, outfile)
我的'result'变量在特定的应用程序页面中查找字符串问题是Google正在更改两个不同页面之间的顺序。有时结果[1]是应用程序名,有时是结果[2];我需要的其他元数据也有同样的问题('updated'、'apkSize'等…)如何处理这些更改。有没有可能用不同的方式刮?谢谢
问题是python循环是not ordered,将其另存为dict not list。用更改
result = [e....]
也
data['appdata']...
与相关问题 更多 >
编程相关推荐