如果需要的话,我可以提供更多的信息和HTML块。我希望能够使用find_all
命令而不仅仅是find
命令将以下块转换为列表理解:
soup.find(class_ = 'info-box').find_parent().find('p').text
当我试着用以下方法自己做的时候:
[p.text for p in soup.find_all(class_= 'info-box').find_parent().find('p')]
我得到以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'ResultSet' object has no attribute 'find_parent'
您将
find_parent()
应用于整个ResultSet
,而不是单个元素。您可以尝试以下操作:相关问题 更多 >
编程相关推荐