【发布时间】:2020-01-24 20:58:09
【问题描述】:
我已经能够从 find 中删除文本,但是在使用 find_all 时会出现错误。
equipmentType = category.find_all("div", {"class":"ExResult-details ExResult-equipmentType"}).text
print(equipmentType)`
`Traceback (most recent call last):
File "scrape.py", line 17, in <module>
equipmentType = category.find_all("div", {"class":"ExResult-details ExResult-equipmentType"}).text
File "/home/bert/.local/lib/python2.7/site-packages/bs4/element.py", line 1578, in __getattr__
"ResultSet object has no attribute '%s'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?" % key
AttributeError: ResultSet object has no attribute 'text'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?
`
【问题讨论】:
-
正如错误所说,它没有属性
text。因为它是一个结果集。您可以遍历列表并从每个元素中获取text
标签: python beautifulsoup screen-scraping