xpath提取<a>标签中的href属性

import requests
from lxml import etree

url = "https://desk.zol.com.cn/dongwu/keaigougou/"
domin = "https://desk.zol.com.cn/"
resp = requests.get(url)
resp.encoding = "gbk"


et = etree.HTML(resp.text)
result = et.xpath("//ul[@class='pic-list2  clearfix']/li/a/@href")
for item in result:
    url = domin+item
    print(url)

运行结果

https://desk.zol.com.cn/https://down10.zol.com.cn/desktoptools/[email protected]
https://desk.zol.com.cn/https://softdl.www.duba.net/softmgr/package/infoflow/package/元气壁纸_29_1.exe
https://desk.zol.com.cn//bizhi/9969_119617_2.html
https://desk.zol.com.cn//bizhi/9899_118991_2.html
https://desk.zol.com.cn//bizhi/9802_118142_2.html
https://desk.zol.com.cn//bizhi/9796_118089_2.html
https://desk.zol.com.cn//bizhi/9795_118088_2.html
https://desk.zol.com.cn//bizhi/9779_117954_2.html
https://desk.zol.com.cn//bizhi/9737_117594_2.html
https://desk.zol.com.cn//bizhi/9661_116882_2.html
https://desk.zol.com.cn//bizhi/9594_116258_2.html
https://desk.zol.com.cn//bizhi/9530_115681_2.html
https://desk.zol.com.cn//bizhi/9415_114598_2.html
https://desk.zol.com.cn//bizhi/9397_114435_2.html
https://desk.zol.com.cn//bizhi/9344_113994_2.html
https://desk.zol.com.cn//bizhi/9338_113943_2.html
https://desk.zol.com.cn//bizhi/9261_113269_2.html
https://desk.zol.com.cn//bizhi/8998_110403_2.html
https://desk.zol.com.cn//bizhi/8939_109799_2.html
https://desk.zol.com.cn//bizhi/8890_109293_2.html
https://desk.zol.com.cn//bizhi/8887_109262_2.html

你可能感兴趣的:(数据库,开发语言)