I need to get all table rows on a page that contain a specific string ‘abc123123’ in them.
The string is inside a TD, but I need the entire TR if it contains the ‘abc123123’ anywhere inside.
I tried this:
userrows = s.findAll('tr', contents = re.compile('abc123123'))
I’m not sure if contents is the write property.
My html looks something like:
<tr>
<td>
</td>
<td><table>.... abc123123 </table><tr>
..
</tr>
<tr>
..
</tr>
..
..
No, the extra keyword arguments beyond the specified ones (
name, attrs, recursive, text, limit) all refer to attributes of the tag you’re searching for.You cannot search for
nameandtextat the same time (if you specifytext, BS ignoresname) so you need separate calls, e.g:Here I’m using a list comprehension since I assume you want a list of the relevant tag objects, as
findAllitself gives you.