The html:
<td>some key
</td>
find without regex:
soup.find(text='some key')
returned None
find with regex
soup.find(text=re.compile('some key'))
returned the td node.
Would anyone point out the difference between the two approaches? "some key" is a literal string without special characters. I noted that there's a carriage return at the end of "some key" that </td>
appears on the next line.
Thank you.
Beautifulsoup uses == to match the content between tags and the search string. Since 'some key\r\n'
!= 'some key'
, the search failed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With