python爬虫练手项目快递单号查询

时间:2023-03-09 09:42:54
python爬虫练手项目快递单号查询
import requests

def main():
try:
num = input('请输入快递单号:')
url = 'http://www.kuaidi100.com/autonumber/autoComNum?resultv2=1&text={}'.format(num)
con = requests.get(url)
con_data = con.json()['auto'][0]['comCode']
urls = 'http://www.kuaidi100.com/query?type={}&postid={}&temp=0.7454983454891435'.format(con_data,num)
wuliu_data = requests.get(urls)
print('**' * 40)
print ('物流公司:' + wuliu_data.json()['com'])
print('**'*40)
wl = wuliu_data.json()['data']
for i in wl[::-1]:
print (i['time'] + ':' + i['context'])
print('--'*40)
except:
main() if __name__ == '__main__':
main()

  练手项目快递单号查询