I'm parsing a html with beautifulsoup. I need to check if a tag have style with something like border.*:.*px
.
I can find all the tags with style by,
soup.find_all(["tr"],style=re.compile(r'border.*:[^:]*px'))
But I've to traverse the html in order, so for a tag, how can I check if it has the style of r'border.*:[^:]*px'
.
I've also refer to Test if an attribute is present in a tag in BeautifulSoup, use the has_attr
method of tag, but is seems it not support regular.
value = re.compile(r'border.*:[^:]*px')
tag.has_attr("{'style':"+value+"}")
but it shows
TypeError Traceback (most recent call last) <ipython-input-202-1e077ea6ea4c> in <module> 1 value = re.compile(r'border.*:[^:]*px') ----> 2 tag.has_attr("{'style':"+value+"}") TypeError: must be str, not _sre.SRE_Pattern