我已经有一段时间了,但似乎无法使用 beautifulsoup 获取结果集对象元素的文本值。这是失败的方法:
def __getNameOfProduct(self, product):
#product is of type bs4.resultset...
for value in product:
print value.find_all("div",class_="proddisc").title.string
它是我自己的标记,所以我没有网址(我正在学习教程),但这是我得到的错误
Traceback (most recent call last):
File "ctd.py", line 64, in <module>
main()
File "ctd.py", line 60, in main
p.getItemsInStock()
File "ctd.py", line 26, in getItemsInStock
return self.__returnItemDetailAsDictionary(itemDetail)
File "ctd.py", line 32, in __returnItemDetailAsDictionary
nameOfProduct = self.__getNameOfProduct(product)
File "ctd.py", line 44, in __getNameOfProduct
print value.find_all("div",class_="proddisc").title.string
AttributeError: 'ResultSet' object has no attribute 'title'
任何帮助将不胜感激。
谢谢!