Я собираю Android Play Store, чтобы заполнить файл json информацией о приложениях.
Вот мой код:
filename = "applications.txt" #file containing apps names com.app...
file = open(filename, "r")
appArray = [line.rstrip() for line in open(filename)]
def createGPscrapjson(pkg_name):
url = 'https://play.google.com/store/apps/details?id=' + pkg_name
response = get(url)
html_soup = BeautifulSoup(response.text, 'html.parser')
bs = BeautifulSoup(response.text,"lxml")
result = {}
details = bs.find_all("div",{"class":"hAyfc"})
for item in details:
label = item.findChild('div', {'class' : 'BgcNfc'})
value = item.findChild('span', {'class' : 'htlgb'})
result[label.text] = value.text
devurl = item.findChild("a",{"class":"hrTbp"})
category = [e.text for e in bs.find_all("span",{"class":"T32cc UAO9ie"})]
appdescription = bs.find("div",{"class":"DWPxHb"})
#developer_link = bs.find("div",{"class":"rAknu"}).find('a').get('href')
developer_link = bs.find("span",{"class":"T32cc UAO9ie"}).find('a').get('href')
rating = [e.text for e in bs.find_all("div",{"class":"BHMmbe"})]
reviewers = [e.text for e in bs.find_all("span",{"class":"AYi5wd TBRnV"})]
price = bs.find("span",{"class":"oocvOe"}).span.find(itemprop="price").get('content')
def developermail():
devinfos = result['Developer'].lower() #Need to be in lower for the regex
devmail = re.search(r'[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}',devinfos).group(0)
if "website" in devmail:
return(devmail[7:])
else:
return(devmail)
data = {}
data['appdata'] = []
data['appdata'].append({
'rating' : rating[0] if len(rating) != 0 else "No rate",
'reviewers' : reviewers[0] if len(reviewers) != 0 else 0,
'app_url' : 'https://play.google.com/store/apps/details?id=' + pkg_name,
'title': html_soup.find(class_="AHFaub").text,
'version' : result['Current Version'],
'pkg_name' : pkg_name,
'developer': result['Offered By'],
'dev_website' : "No website" if "mailto:" in devurl.get('href') else devurl.get('href'),
'downloads' : result['Installs'],
'category' : category[1],
'description' : appdescription.text,
'price' : price,
'developer_link' :developer_link,
'operating_system' : "Android",
'email' : developermail(),
'updated': result['Updated']
})
jsonfile_one = "scrapGPdata.json" #Get all the appS infos in one JSON
with open(jsonfile_one, 'a+') as outfile_one:
json.dump(data, outfile_one)
for i in range(0,len(appArray)):
pdb.set_trace()
createGPscrapjson(appArray[i])
Когда я выполняю свой код, у меня появляется эта ошибка:
Traceback (последний последний вызов): Файл "ScrapAppPage.py ", строка 141, в файле createGPscrapjson (appArray [i])" ScrapAppPage.py ", строка 49, в файле createGPscrapjson price = bs.find (" span ", {" class ":" oocvOe "}). span.find (itemprop = "price"). get ('content') AttributeError: у объекта 'NoneType' нет атрибута 'span'
Где моя ошибка и как я могу использовать режим отладки (pdb) чтобы узнать, как заполняется мой файл json?