"""
数据地址：
https://www.stats.gov.cn/sj/pcsj/rkpc/7rp/zk/lefte.htm
xpath 进行数据爬取：->xml转换
//根节点
//节点
@属性
//"D:/用户[@软件安装位置]"

"""
import requests
from lxml import etree


def Tools(url):

    headers = {
        'referer': 'https://www.stats.gov.cn/sj/pcsj/rkpc/7rp/zk/indexce.htm',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0'
    }

    response = requests.get(url,headers=headers)

    return response



url = 'https://www.stats.gov.cn/sj/pcsj/rkpc/7rp/zk/lefte.htm'
response=Tools(url).content.decode('gbk')
html=etree.HTML(response)
title=html.xpath('//ul[@id="foldinglist"]/li/a')
details=html.xpath('//ul[@id="foldinglist"]/li/a/@href')
for t,d in zip(title,details):
    urls='https://www.stats.gov.cn/sj/pcsj/rkpc/7rp'+d
    print(urls)