Hallo also ich find_all auf eine beautifulsoup object
, und finde etwas, das ist eine bs4.element.ResultSet object
oder eine list
.beasesoup: find_all auf bs4.element.ResultSet Objekt oder Liste?
Ich möchte find_all weiter dort tun, aber es ist nicht auf eine bs4.element.ResultSet object
erlaubt. Ich kann jedes Element der bs4.element.ResultSet object
durchlaufen, um find_all zu tun. Kann ich Schleifen vermeiden und sie einfach wieder in beautifulsoup object
konvertieren?
Siehe Code für Details bitte. Dank
html_1 = """
<table>
<thead>
<tr class="myClass">
<th>A</th>
<th>B</th>
<th>C</th>
<th>D</th>
</tr>
</thead>
</table>
"""
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
Nach dem Kopieren des Ergebnisses der soup.find_all th_all, werden Änderungen reflektieren, um th_all Suppe? –
Ja wird es. Hängt davon ab, welche Funktion Sie verwenden. Siehe: https://beautiful-soup-4.readthedocs.io/en/latest/#modifying-the-tree –