【发布时间】:2019-12-24 10:41:04
【问题描述】:
我正在尝试学习如何抓取网站,因此不使用 API。我正在尝试抓取 eBay 的网站,我的脚本运行了几分钟,但由于错误提示“AttributeError: 'NoneType' object has no attribute 'text'”而停止。我做了尽职调查并在 Google/StackOverflow 帮助上进行了搜索,但找不到任何帮助。错误指向下面的代码,但我不知道如何修复它。
total_sold_price = soup.find('span', {'class': 'vi-qtyS-hot-red'}).text
if total_sold_price:
total_sold_price = soup.find('span', {'class': 'vi-qtyS-hot-red'}).text
else:
try:
total_sold_price = soup.find('a', {'class': 'vi-txt-underline'}).text
except Exception as e:
print(e)
total_sold_price = ""
完整代码:https://pastebin.com/xS4bAwZK
提前致谢,非常感谢。
【问题讨论】:
标签: python beautifulsoup