regex error in soup.find_all()?

22 views
Skip to first unread message

Swing

unread,
Mar 28, 2016, 7:36:12 AM3/28/16
to beautifulsoup
code:

strPtn = r"jd-details api"

strin
= '''
<div class="jd-details api-1">aaaaaa</div>
<div class="jd-details">bbbbbbbbb</div>
<div class="jd-details api-2">ccccccc</div>'''


soup
= BeautifulSoup(strin, "html.parser")
all
= soup.find_all("div", class_=re.compile(strPtn))
print len(all)

This code will print 0 !
if strPth changed to this:
strPtn = r"jd-details"

output is 3, include all 3 'div', but the middle one is not what I want.

strPtn = r"jd-details api apilevel-\?\?"

This also print 0.

A bug?

Swing

unread,
Mar 28, 2016, 8:39:31 AM3/28/16
to beautifulsoup
I get it....
It's another class!
Reply all
Reply to author
Forward
0 new messages