beautifulsoup find_all()返回空列表

时间:2020-04-05 02:45:02

标签: python beautifulsoup

我正在使用bs4解析xml,但是我可以根据需要使用find方法提取标记“ w:tl”,但是find_all(name =“ w:tl”)方法返回空列表,而只有find_all(lambda) e:e.name ==“ w:tl”)返回预期的结果,即返回带有标签'w:tl'的所有内容。但是奇怪的是find_all('w')没问题。那为什么呢?

from bs4 import BeautifulSoup
openxml = '''
<head>
<p id='p1'>12</p>
<w:tl class='p3'>12</w:tl>
<w:tl class='p3'>11</w:tl>
<w:tl>11</w:tl>
<w:tl>11</w:tl>
<w>11</w>
<w>11</w>
<p></p>
</head>

'''
url_soup = BeautifulSoup(openxml,'lxml')
# #
url_soup.find_all(lambda e: e.name == "w:tl")
url_soup.find_all(name="w:tl")
url_soup.find("w:tbl")
url_soup.find_all(name="w")

0 个答案:

没有答案