I am trying to use the BeautifulSoup (bs4) package in Python2.7 to find the following tag in an html document:
You can check the style
to have left:408px
and height:9px
inside it:
soup.find('div', style=lambda value: value and 'left:408px' in value and 'height:9px' in value)
Or:
import re
soup.find('div', style=re.compile(r'left:408px.*?height:9px'))
Or:
soup.select_one('div[style*="408px"]')
Note that, in general, style properties are not reliable to use for locating elements. See if there is anything else - check the parent, sibling elements, or may be there is a corresponding label near the element.
Note that, a more appropriate CSS selector would be div[style*="left:408px"][style*="height:9px"]
, but because of the limited CSS selector support and this bug, it is not gonna work as is.