import urllib.request
from lxml import etree
def get_data(url):
'''
:param url: 请求地址
:return: None
'''
response=urllib.request.urlopen(url=url)
html=response.read().decode("utf-8")
# *************** Begin *************** #
parse = etree.HTML(html)
# 写入xpath路径
item_list = parse.xpath("//div[@class='left']/ul/li/span/a/text()")
#item_list = parse.xpath("/html/body/div[2]/div[1]/ul/li/span/a.text()")
# *************** End ***************** #
print(item_list)
头歌xpath解析网页
于 2022-04-27 13:27:38 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)