|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 Stubborn 于 2019-2-26 02:28 编辑
关于顺丰快递单验证吗,拖拽重合的那种,大致用那个模块解决,自己想弄个查快递的,有木有源码或者什么,没有的话告诉我顺丰的怎么解决验证码
- import requests
- #查询首次请求 POST
- # resultv2: 1
- # text: 1202752875967
- #url = "https://www.kuaidi100.com/autonumber/autoComNum?"
- #数据返回 GET
- # type: yunda
- # postid: 1202752875967
- #url2 = "https://www.kuaidi100.com/query?"
- def check(text):
- headers={"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64)"}
- data = {'resultv2': "1", "text": text}
- url = "https://www.kuaidi100.com/autonumber/autoComNum?"
- reponse = requests.post(url=url, data=data,headers=headers)
- type = reponse.json()['auto'][0]['comCode']
- def login(text,type):
- url = "https://www.kuaidi100.com/query?"
- params = {
- 'type': type,
- 'postid': text
- }
- reponse = requests.get(url=url,params=params)
- for each in reponse.json()['data']:
- print(each['context'],end='')
- print(each['ftime'])
- return login(text,type)
- if __name__ == '__main__':
- text = input('请输入需要查询的快递单号')
- check(text)
复制代码- import json,requests
- import random
- def searchPackage(dh):
- state={
- '0':'在途',
- '1':'揽件',
- '2':'疑难',
- '3':'签收',
- '4':'退签',
- '5':'派件',
- '6':'退回',
- }
- #请求头
- head = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36'
- }
- packageNum = dh
- url1 = 'http://www.kuaidi100.com/autonumber/autoComNum?resultv2=1&text=' + packageNum
- #用url1查询运单号对应的快递公司,如中通,返回:zhongtong。
- try:
- companyName = json.loads(requests.get(url1, headers=head).text)['auto'][0]['comCode']
- except Exception as e:
- time = ''
- context = ''
- tracking = ''
- carrier = '单号异常'
- else:
- #在用url2查询和运单号、快递公司来查询快递详情,结果是一个json文件,用dict保存在resultdict中。
- url2 = 'http://www.kuaidi100.com/query?type=' + companyName + '&postid=' + packageNum
- jsonContext = json.loads(requests.get(url2, headers=head).text)
- try:
- time = jsonContext['data'][0]['time']
- context = jsonContext['data'][0]['context']
- tracking = state[jsonContext['state']]
- carrier = jsonContext['com']
- except Exception as e2:
- time = ''
- context = ''
- tracking = ''
- carrier = '查无记录'
- finally:
- print(dh,end=" ")
- print(carrier,end=" ")
- print(time,end=" ")
- print(tracking,end=" ")
- print(context)
- while True:
- odd = input("请输入运单号,存在多条运单号时使用','进行分隔:\n").split(',')
- if odd:
- print('快递单号 快递公司 最后时间 状态 地点和跟踪进度')
- for i in odd:
- if i != '':
- searchPackage(i)
- again = input("\n\n\n查询结束,按'Q'键再次查询,其余任意键退出:\n")
- if again == 'Q':
- break
- else:
- continue
- else:
- break
- print("GoodBye")
- input("按任意键关闭")
复制代码
|
|