python怎么去除html标签


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

import re

from bs4 import BeautifulSoup

from lxml import etree

  

html = '<p>你好</p><br/><font>哈哈</font><b>大家好</b>'

  

# 方法一

pattern = re.compile(r'<[^>]+>',re.S)

result = pattern.sub('', html)

print(result)

 <br># 方法二

soup = BeautifulSoup(html,'html.parser')

print(soup.get_text())

  

# 方法三

response = etree.HTML(text=html)

# print(dir(response))

print(response.xpath('string(.)'))

  

  

# 你好哈哈大家好

# 你好哈哈大家好

# 你好哈哈大家好

【推荐:python视频教程】

以上就是python怎么去除html标签的详细内容,更多文章请关注木庄网络博客!!

返回前面的内容

相关阅读 >>

Python可以输入中文吗

Python爬虫学到什么程度能找到工作

Python学习日记(50)--paramiko

Python安装的第三方库怎么删除

Python实现的端口扫描功能

Python函数之dir()函数

Python怎么print汉字

教你一招用Python破解斗地主残局

利用Python执行shell脚本 并动态传参 及subprocess基本使用

Python的快速排序方法

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...