【发布时间】:2023-04-04 00:40:01
【问题描述】:
我正在尝试使用来自 bs4/Python 3 的 BeautifulSoup 来提取 CData。但是,每当我使用以下内容搜索它时,它都会返回一个空结果。谁能指出我做错了什么?
from bs4 import BeautifulSoup,CData
txt = '''<foobar>We have
<![CDATA[some data here]]>
and more.
</foobar>'''
soup = BeautifulSoup(txt)
for cd in soup.findAll(text=True):
if isinstance(cd, CData):
print('CData contents: %r' % cd)
【问题讨论】:
-
在答案here 中可以找到类似的代码,我假设您在这里得到了这个。
标签: python python-3.x beautifulsoup cdata