«
Xpath网页爬虫简述[python]

时间:2022-1-17    作者:Deri    分类: Python


基础代码如下,详细使用方法参考:
查看详细用法

组件安装:pip install lxml

# -*- coding:utf-8 -*-
import requests
from lxml import etree

url="http://music.baidu.com"
r=requests.get(url)
r.encoding="utf-8"
html=r.text
# print(html)
selector = etree.HTML(html)
Tlist=selector.xpath('//body/div/div/div/div/div/ul/li/a/text()')
for T in Tlist:
    print(T)

标签: python lxml xpath 爬虫