如何在python bs4中修复“NoneType”对象没有属性“text”

2024-10-03 23:30:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用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'

Tags: 代码textinfortitle错误findproduct