I'm beginning with Python and Beautiful Soup and I'm scraping Google PlayStore and applications metadata in a JSON file. Here is my code :
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)
My 'result' variable looks for a string in a specific app page the problem is that Google is changing the order between two different pages. Sometimes result[1] is the application name, sometimes it's result[2]; Same problems for other metadata I need ('updated', 'apkSize', etc...) How can I deal with these changes. Is it possible to scrape in a different way? Thank you