string vs text in find method

31 views
Skip to first unread message

Om Damani

unread,
Aug 16, 2017, 3:56:35 PM8/16/17
to beautifulsoup
As per documentation at https://www.crummy.com/software/BeautifulSoup/bs4/doc/index.html#string , for find method

'The string argument is new in Beautiful Soup 4.4.0. In earlier versions it was called text:'

Problem is this is at odds with '.strings' vs '.text' behaviour of a tag. Say the tag is

<a class="" href="http://moodle.iitb.ac.in/mod/forum/view.php?id=41349" onclick=""><img alt=" " class="iconlarge activityicon" role="presentation" src="http://moodle.iitb.ac.in/theme/image.php/clean/forum/1495198886/icon"/><span class="instancename">News forum</span></a>

For this "a" tag, .string is None while .text is "News forum".

But inside the find method, if I pass the argument: text=re.compile('forum'), it doe not match this tag, just the way string=re.compile('forum') does not match.

That is, after

tag = content.find("a", text=re.compile('forum'))

tag has value None, assuming content includes the above tag.

Thanks,

Om

Reply all
Reply to author
Forward
0 new messages