小编tov*_*eod的帖子

Beautifulsoup使用`find_all`逐个文本找到元素,无论它是否有元素

例如

bs = BeautifulSoup("<html><a>sometext</a></html>")
print bs.find_all("a",text=re.compile(r"some"))
Run Code Online (Sandbox Code Playgroud)

返回[<a>sometext</a>],但当搜索的元素有一个孩子,即img

bs = BeautifulSoup("<html><a>sometext<img /></a></html>")
print bs.find_all("a",text=re.compile(r"some"))
Run Code Online (Sandbox Code Playgroud)

它返回 []

有没有办法用来find_all匹配后面的例子?

python beautifulsoup

5
推荐指数
1
解决办法
8556
查看次数

标签 统计

beautifulsoup ×1

python ×1