【发布时间】:2018-03-12 16:29:42
【问题描述】:
假设我有以下:
<!--NAMED COMMENT<trans-unit id="1" reformat="yes">
<source>foo</source>
<target>bar</target>
</trans-unit>-->
我想回来
<trans-unit id="1" reformat="yes">
<source>foo</source>
<target>bar</target>
</trans-unit>
我似乎无法在问题中剥离 cmets。我可以访问这些 cmets:
soup = BeautifulSoup(xlf, "lxml")
comments = soup.find_all(text=lambda text: isinstance(text, Comment))
for comment in comments:
print(comment)
但不能返回带有这些更改的增补对象。任何帮助将不胜感激。
【问题讨论】:
-
那么,您想从您的代码正在打印的字符串中删除
NAMED COMMENT部分吗?
标签: python python-3.x beautifulsoup