有什么办法可以将bs4.element.ResultSet转换为bs4.BeautifulSoup?

时间:2020-04-19 06:06:13

标签: python web-scraping beautifulsoup

我正在尝试抓取网页并从表格中提取信息

html_soup = soup.find_all(lambda tag: tag.name == 'table' and tag.get('class') == ['wikitable']) 

由于使用了上面的代码,因此html_soup的类型为bs4.element.ResultSet,这不允许将函数用作find_all。有什么办法可以将html_soup转换或类型转换回bs4.BeautifulSoup。

1 个答案:

答案 0 :(得分:0)

html_soup基本上是一个列表。

您可以在find_all的各个元素上使用html_soup

如果您的html_soup[0].find_all()不为空,则

html_soup应该可以工作。