如何从python中的字符串中获取纯文本?

2024-09-30 01:21:47 发布

您现在位置:Python中文网/ 问答频道 /正文

其中有一个字符串,其中包含许多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标签?


Tags: 字符串namebrgthomedebianfindworkspace
1条回答
网友
1楼 · 发布于 2024-09-30 01:21:47

使用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



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

请参阅Extracting text from HTML file using Python以获取参考。在

相关问题 更多 >

    热门问题