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如何将名称映射到序列的元素中(代码)

如何用Python代码温度转换?

《流畅的Python》怎么样

Python爬虫框架scrapy的简单介绍

Python中的array数组模块相关使用

Python除了爬虫还可以做什么

Python基本语法

Python如何求列表平均值?

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




打赏

取消

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

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

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

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

评论

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