使用BeautifulSoup查找特定标签

Jan*_*ane 22 python beautifulsoup

我可以轻松地使用BS遍历通用标签,但我不知道如何查找特定标签.例如,我怎样才能找到所有出现的<div style="width=300px;">?这可能与BS有关吗?

pyf*_*unc 31

以下应该有效

soup = BeautifulSoup(htmlstring)
soup.findAll('div', style="width=300px;")
Run Code Online (Sandbox Code Playgroud)

有几种方法可以搜索标签.

有关更多文本要理解和使用它


Moh*_*med 7

与bs4的事情有所改变.所以代码应该是这样的

soup = BeautifulSoup(htmlstring,'lxml') soup.find_all('div', {'style':"width=300px;"})