Я начинаю с Python и Beautiful Soup и собираю метаданные Google PlayStore и приложений в файл 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 меняет порядок между двумя разными страницами.Иногда result [1] - это имя приложения, иногда - result [2];Те же проблемы для других метаданных, которые мне нужны («обновление», «apkSize» и т. Д.). Как я могу справиться с этими изменениями.Можно ли по-другому скрести?Спасибо