我正在用beautifulsoup解析一个html。我需要检查标记是否具有类似border.*:.*px
的样式。你知道吗
我能找到所有有风格的标签
soup.find_all(["tr"],style=re.compile(r'border.*:[^:]*px'))
但是我必须按顺序遍历html,因此对于标记,如何检查它是否具有r'border.*:[^:]*px'
样式。你知道吗
我也参考了Test if an attribute is present in a tag in BeautifulSoup,使用了tag的has_attr
方法,但是它似乎不支持正则。你知道吗
value = re.compile(r'border.*:[^:]*px')
tag.has_attr("{'style':"+value+"}")
但它显示了
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
我没有找到一个方法来得到它。所以我使用
re
模块作为解决方法。你知道吗相关问题 更多 >
编程相关推荐