import requests
from lxml import etree
url = 'https://www.aqistudy.cn/historydata/'
headers = {'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/"}
res = requests.get(url = url,headers = headers)
tree = etree.HTML(res.text)
city = open('pm_city.txt','w',encoding='utf-8')
hot_city = tree.xpath('.//div[@class="bottom"]/ul/li')
for i in hot_city:
hot = i.xpath('./a/text()')[0]
print(hot,end = ' ')
city.write(hot+' ')
print(len(hot_city))
city.write('\n')
all_city = tree.xpath('//div[@class="bottom"]/ul/div[2]/li')
for a in all_city:
name = a.xpath('./a/text()')[0]
print(name,end=' ')
city.write(name+' ')
print(len(all_city))
