您当前的位置: 首页 >  爬虫

黑马蓝汐

暂无认证

  • 2浏览

    0关注

    89博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

爬虫中lxml模块-tostring的用法

黑马蓝汐 发布时间:2021-11-21 19:42:06 ,浏览量:2

每日分享:

 

我们不需要迎合所有人,只需要过滤出来和自己同频的人就OK了

  • lxml.etree.HTML(html_str)可以自动补齐标签
  • 可以将element对象转换为HTML字符串
  • 爬虫如果使用lxml来提取数据,应以lxml.etree.tostring的返回结果作为提取数据的依据

例:

from lxml import etree
text = ''' 
  • first item
  • second item
  • third item
  • fourth item
  • fifth item
''' # 转化为element对象 html = etree.HTML(text) print(html) print('-'*20) print(etree.tostring(html))

结果:

关注
打赏
1643043582
查看更多评论
立即登录/注册

微信扫码登录

0.0382s