beautifulsoup: find_all on bs4.element.ResultSet object or list?
ResultSet
class is a subclass of a list and not a Tag
class which has the find*
methods defined. Looping through the results of find_all()
is the most common approach:
th_all = soup.find_all('th')result = []for th in th_all: result.extend(th.find_all(text='A'))
Usually, CSS selectors may help you solve it in one go except that not everything you can do with find_all()
is possible with the select()
method. For instance, there is no "text" search available in bs4
CSS selectors. But, if, for example, you had to find all, say, b
elements inside th
elements, you could do:
soup.select("th td")