开发者

Extract divs with at least one class in BeautifulSoup

开发者 https://www.devze.com 2022-12-20 15:32 出处:网络
Supo开发者_JAVA百科se you have a web page with a lot of this: <div class=\"story cid-8797378263432 l-es headline-story thumbnail-true\">

Supo开发者_JAVA百科se you have a web page with a lot of this:

<div class="story cid-8797378263432 l-es headline-story thumbnail-true">

where cid-nnnnnnnnnnnn class can vary. How would you get all the divs with BeautifulSoup?

I tried:

soup.find('div', {'class': 'story'})

but that didn't work. Seems to look for the divs with ONLY the story class.


Or you can just use soup.findAll('div', 'story') which doesn't seem to have that bug.


It's a bug: Launchpad bug report. The report also contains a workaround:

soup.findAll('div', {'class': re.compile(r'\bstory\b')})
0

精彩评论

暂无评论...
验证码 换一张
取 消