Does anyone know how to use bs4 in python to search for multiple tags, one of which will need an attribute?
For example, to search for all occurrences of a single tag with an attribute, I know that I can do this:
tr_list = soup_object.find_all('tr', id=True)
And I know that I can do this too:
tag_list = soup_object.find_all(['a', 'b', 'p', 'li'])
But I can’t understand how to combine the two statements, which theoretically give me a list in the order in which all these html tags appear, with each tr tag having an identifier.
The html snippet will look something like this:
<tr id="uniqueID">
<td nowrap="" valign="baseline" width="8%">
<b>
A_time_as_text
</b>
</td>
<td class="storyTitle">
<a href="a_link.com" target="_new">
some_text
</a>
<b>
a_headline_as_text
</b>
a_number_as_text
</td>
</tr>
<tr>
<td>
<br/>
</td>
<td class="st-Art">
<ul>
<li>
more_text_text_text
<strong>
more_text_text_text
<font color="228822">
more_text_text_text
</font>
</strong>
more_text_text_text
</li>
<li>
more_text_text_text
<ul>
<li>
more_text_text_text
</li>
</ul>
</li>
</ul>
</td>
</tr>
<tr>
</tr>
Thanks for the help!
source
share