【发布时间】:2013-04-01 07:28:48
【问题描述】:
我只是遇到了正则表达式的障碍,不知道为什么这不起作用。
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 文档,但我的正则表达式不起作用。如果我用4(最初在html中)替换\d{1},它就成功了。
【问题讨论】:
标签: python regex python-2.7 beautifulsoup