import requests
import random
def getHTML(url):
return requests.get(url, headers=headers)
headers = {
"Accept-Language": "zh-CN,zh;q=0.9",
"Referer": "https://www.kuaidi100.com/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"
}
posdid = input('请输入快递号:')
# 获取快递公司
r = getHTML(f'https://www.kuaidi100.com/autonumber/autoComNum?resultv2=1&text={posdid}')
company = r.json()['auto'][0]['comCode']
print('快递公司:' + r.json()['auto'][0]['comCode'])
# 获取cookies
res = getHTML(f'https://www.kuaidi100.com/')
csrftoken = res.headers['Set-Cookie'].split('; ')[0].split('=')[1]
headers['Cookie'] = f"csrftoken={csrftoken}; Hm_lvt_22ea01af58ba2be0fec7c11b25e88e6c=1606364424,1606364488,1606558121,1606569237; Hm_lpvt_22ea01af58ba2be0fec7c11b25e88e6c=1606569234"
# 获取物流信息
res = getHTML(f'https://www.kuaidi100.com/query?type={company}&postid={posdid}&temp={random.random()}&phone=')
print(res.json())
for i in res.json()['data']:
print(i['time'] + i['context'])
快递100 python
最新推荐文章于 2023-07-22 17:23:03 发布