您当前的位置: 首页 >  Python

Python爬虫:使用lxml解析网页内容

彭世瑜 发布时间:2018-07-24 23:07:02 ,浏览量:6

安装
pip install lxml
代码示例

from lxml import etree

text = """

    
        这是标题
    
    
        
这是内容
""" html = etree.HTML(text) # 使用xpath解析 titles = html.xpath("//title") for title in titles: print(title.text) # 使用css解析 titles = html.cssselect("title") for title in titles: print(title.text)
关注
打赏
1688896170
查看更多评论

彭世瑜

暂无认证

  • 6浏览

    0关注

    2727博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.4231s