我正在用python中的butifulsoup module
进行抓取
我的代码:
for cactus in cactus_product:
price = cactus.find("span", class_="._89yzn").text
title = cactus.find("span", class_="._2tW1I").text
f.write(title + "," + price)
错误
Traceback (most recent call last):
File "C:\Users\Technicalsmirchis\python_scraping_tutorial\scraper.py", line 24, in <module>
price = cactus.find('span', class_="_89yzn").text
AttributeError: 'NoneType' object has no attribute 'text'
这是因为
find
函数返回None,这意味着它没有找到所需的元素。 您可以添加try-except
块以检查此类异常或if x is not None:
相关问题 更多 >
编程相关推荐