我正在努力从属性值为h5和ls3的HTML文件中提取所有标记,但我不确定如何格式化搜索,以便它不会返回h5的所有实例和ls3的所有实例
regex = re.compile('h5')
re2 = re.compile('ls3')
ly = []
for EachPart in soup.find_all("div", {"class": regex}):
ly.append(EachPart)
这目前只搜索h5(正如预期的那样),但是如何将find_all
搜索格式化为与regex
一起搜索re2
?实际上,下面我需要拉标签,有h5和ls3,而不是那些专门的h5
HTML标记示例:
<div class="t m0 x42 h5 y18b ff2 fs2 fc0 sc0 ls0 ws0">total </div>
<div class="t m0 xbd h5 y18b ff2 fs2 fc0 sc0 ls0 ws0"> </div>
<div class="t m0 x79 h5 y18b ff2 fs2 fc0 sc0 ls3 ws0">£m<span class="ls0"> </span></div>
<div class="t m0 x0 h5 y628 ff2 fs2 fc0 sc0 ls3 ws0">17.<span class="ls0"> <span class="_ _4"></span>Website policy<span class="_ _0"></span> </span></div>
将css选择器与和语法一起使用。下面指定具有这两个属性的元素。比
find
和regex更有效相关问题 更多 >
编程相关推荐