我只是遇到了正则表达式的障碍,不知道为什么这不起作用。
这是 BeautifulSoup 文档所说的:
soup.find_all(class_=re.compile("itl"))
# [<p class="title"><b>The Dormouse's story</b></p>]
这是我的html:
<a href="exam.com" title="Keeper: Jay" class="pos_text">Aouate</a></span><span class="pos_text pos3_l_4">
我正在尝试匹配span
标签(最后一个位置)。
>>> if soup.find(class_=re.compile("pos_text pos3_l_\d{1}")):
print "Yes"
# prints nothing - indicating there is no such pattern in the html
所以,我只是在重复 BS4 文档,除了我的正则表达式不起作用。果然,如果我\d{1}
用4
(最初在 html 中)替换它就成功了。