![](/img/trans.png)
[英]Hello world! I am stuck with this error. Can anyone assist me fix this? I would appreciate any form of assessment
[英]I am trying to scrape a website for my project but I am stuck with an error. Take a look and let me know if anyone have suggestion for this
html_text = requests.get('https://www.trustpilot.com/categories/restaurants_bars?
numberofreviews=0&status=claimed&timeperiod=0').text
soup = BeautifulSoup(html_text, 'lxml')
restaurants = soup.find_all('a', class_ = 'internal___1jK0Z wrapper___26yB4')
for index, restaurant in enumerate(restaurants):
name = restaurant.find('div', class_ = 'businessTitle___152-c').text
rating = restaurant.find('div', class_ = 'textRating___3F1NO').text
with open('{index}.csv', 'a') as f:
f.write(name)
f.write(',')
f.write(rating)
f.write('\n')
print('File saved')
這是引發錯誤的代碼。
回溯(最后一次調用):文件“main.py”,第 8 行,名稱 = restaurant.find('div', class_ = 'businessTitle___152-c').text AttributeError: 'NoneType' object 沒有屬性 'text '
您正在嘗試訪問None
類型的 object 的屬性,可能您的一個查詢返回None
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.