使用xpath提取href属性值

import requests
from lxml import etree

url = "http://www.baidu.com"
resp = requests.get(url)
resp.encoding="utf-8"

html = etree.HTML(resp.text)
linklist = html.xpath("//a/@href")

for item in linklist:
    print(item)

你可能感兴趣的:(python)