0

有一个带有许多 html 标签的字符串,如下所示,
u'find /home/tiger/workspace&nbsp; -name "[0-9]*"<br />find /home/tiger/workspace&nbsp; -name "[!0-9]*"<br />find /home/tiger/workspace&nbsp; -name "[^0-9]*"<br /><br />\u627e\u51fa\u6240\u6709\u5305\u542b\u6570\u5b57\u7684\u6587\u4ef6\uff0c\u4e0d\u5305\u542b\u6570\u5b57\u7684\u6587\u4ef6\u3002<br />tiger@debian:~$ find /home/tiger&nbsp; -name "*[0-9]*"&nbsp; &gt;kan1<br />tiger@debian:~$ find /home/tiger&nbsp; -name "[0-9]*"&nbsp; &gt;kan2<br />tiger@debian:~$ find /home/tiger&nbsp; -name "*[0-9]"&nbsp; &gt;kan3<br /><br /><br />\u5305\u542b\u6570\u5b57\uff0c\u6570\u5b57\u5f00\u5934\uff0c\u6570\u5b57\u7ed3\u5c3e'

如何获取字符串中的纯文本以删除 html 标签?

4

1 回答 1

0

使用html2text库:

>>> print html2text.html2text(s)
find /home/tiger/workspace&nbsp_place_holder; -name "[0-9]*"

find /home/tiger/workspace&nbsp_place_holder; -name "[!0-9]*"

find /home/tiger/workspace&nbsp_place_holder; -name "[^0-9]*"


找出所有包含数字的文件,不包含数字的文件。

tiger@debian:~$ find /home/tiger&nbsp_place_holder; -name
"*[0-9]*"&nbsp_place_holder; >kan1

tiger@debian:~$ find /home/tiger&nbsp_place_holder; -name
"[0-9]*"&nbsp_place_holder; >kan2

tiger@debian:~$ find /home/tiger&nbsp_place_holder; -name
"*[0-9]"&nbsp_place_holder; >kan3



包含数字,数字开头,数字结尾

请参阅使用 Python 从 HTML 文件中提取文本以供参考。

于 2013-04-07T05:10:14.283 回答