嗨所以我在一个beautifulsoup对象上应用find_all,并找到一些东西,它是一个bs4.element.ResultSet对象或一个列表.
我想在那里进一步做find_all,但是bs4.element.ResultSet对象不允许这样做.我可以循环遍历bs4.element.ResultSet对象的每个元素来执行find_all.但我可以避免循环并将其转换回beautifulsoup对象吗?
请参阅代码了解详情.谢谢
html_1 = """
ABCD
"""
soup = BeautifulSoup(html_1, 'html.parser')
type(soup) #bs4.BeautifulSoup
# do find_all on beautifulsoup object
th_all = soup.find_all('th')
# the result is of type bs4.element.ResultSet or similarly list
type(th_all) #bs4.element.ResultSet
type(th_all[0:1]) #list
# now I want to further do find_all
th_all.find_all(text='A') #not work
# can I avoid this need of loop?
for th in th_all:
th.find_all(text='A') #works
版权声明:本文为weixin_30582757原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。