【发布时间】:2016-05-03 21:34:48
【问题描述】:
我希望下面的代码
from bs4 import BeautifulSoup
import re
sopa = BeautifulSoup('<ol><li>this is a string</li></ol>')
sopa.find_all(string=re.compile("a"))
会返回[u'this is a string'],但它会返回[]。为什么?
BeautifulSoup 4 文档给出了这个例子:
soup.find_all(string=re.compile("Dormouse"))
当作用于爱丽丝梦游仙境节选的汤时,应该返回
[u"The Dormouse's story", u"The Dormouse's story"]
文档还说 bs4 使用 re.match()(匹配字符串的开头),但其他地方(以及官方文档中的这个示例)指示 re.search(),并将正则表达式 "a" 更改为 @ 987654329@无论如何对结果都没有影响。
【问题讨论】:
-
已解决。版本 text
标签: regex python-2.7 beautifulsoup