【发布时间】:2019-12-27 09:45:21
【问题描述】:
import requests
from bs4 import BeautifulSoup
request = requests.get("https://www.jumia.com.ng/ergonomic-office-swivel-chair-universal-mpg200557.html")
content = request.content
soup = BeautifulSoup(content, "html.parser")
element = soup.find("span", {"dir" : "ltr", "data-price" : "", "class" : "-b -ltr -fs24"})
print(element.text)
Traceback (most recent call last):
File "C:/Users/EMMRAWL/PycharmProjects/Price of Chair/scr/app.py", line 9, in <module>
print(element.text)
AttributeError: 'NoneType' object has no attribute 'text'
Process finished with exit code 1
【问题讨论】:
-
.find如果找不到匹配项,则返回None。因此,请确保您的匹配项已找到或不像if element:这样。 -
谢谢。所以可能是链接不正确,或者元素字典
-
我看到了错误
-
element = soup.find("span", {"dir" : "ltr", "data-price" : "", "class" : "-b -ltr -tar -fs24" })
-
元素字典中“-ltr”和“-fs24”之间有一个“-tar”
标签: python beautifulsoup attributeerror