Python&BeautifulSoup-我可以重复使用findAll函数吗?

问题描述 投票:2回答:2

在BS文档中,他们写道:

Remember the soup.head.title trick from Navigating using tag names? That trick works by repeatedly calling find():
soup.head.title
# <title>The Dormouse's story</title>

soup.find("head").find("title")
# <title>The Dormouse's story</title>

我可以对findAll做同样的事情吗?无法正常运作...

python beautifulsoup findall
2个回答
2
投票

否,您不能链接findAll,因为它返回一个bs4.element.ResultSet,它基本上是没有findAll方法的列表。如果您尝试过此操作,则将出现明显的错误。


0
投票

如果所有搜索都给出一个结果,或者您知道确切的索引,可以像这样链接它:

© www.soinside.com 2019 - 2024. All rights reserved.