beautifulsoup find text with and without regex
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.
精彩评论