'Find a specific tag with BeautifulSoup
I can traverse generic tags easily with BS, but I don't know how to find specific tags. For example, how can I find all occurances of <div style="width=300px;">? Is this possible with BS?
Solution 1:[1]
The following should work
soup = BeautifulSoup(htmlstring)
soup.findAll('div', style="width=300px;")
There are couple of ways to search for tags.
For more text to understand and use it
Solution 2:[2]
with bs4 things have changed a little. so the code should look like this
soup = BeautifulSoup(htmlstring,'lxml')
soup.find_all('div', {'style':"width=300px;"})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | grantr |
| Solution 2 | 0xMH |
