本文最后更新于 916 天前,其中的信息可能已经有所发展或是发生改变。
代码语言:javascript复制import json
from tkinter import *
import requests
def getType(postId):
url='http://www.kuaidi100.com/autonumber/autoComNum?resultv2=1&text=' postId
rs=requests.get(url)
postTypeInfo=json.loads(rs.text)
print(postTypeInfo['comCode'])
if not postTypeInfo['auto']:
postType='xxx'
else:
postType=postTypeInfo['auto'][0]['comCode']
return postType
def getMessage(postType,postId):
if postType=='xxx':
messageAll=u'Input your postId'
else:
url='http://www.kuaidi100.com/query?type=' postType '&postid=' postId
print(url)
rs=requests.get(url)
messageInfo=json.loads(rs.text)
if messageInfo['message']=='ok':
messageAll=u' PostId:' messageInfo['nu'] 'n'
u' PostCompany:' messageInfo['com'] 'n'
u' PostInformation:' 'n'
dataAll=messageInfo['data']
for item in dataAll:
messageAll=messageAll u' Time:' item['time'] 'n'
' ' item['context'] 'n'
else:
messageAll=messageInfo['message']
return messageAll
def action(postId,e,e1):
e1.set(getMessage(getType(e.get()), e.get()))
def main():
postId='88307061538'
#print(getMessage(getType(postId),postId))
root=Tk()
root.title(u'postSearch')
root.minsize(500,500)
e=StringVar()
e.set(u'804621983284589441')
e1=StringVar()
entry=Entry(root,bg='#ffffff',width=30,textvariable=e).place(x=30,y=30,anchor='nw')
message = Message(root,textvariable=e1,width=377).place(x=30, y=70, anchor='nw')
bt=Button(root,bg='white',text=u'Search',width=10,height=1,command=lambda :action(postId,e,e1)).place(x=320,y=26,anchor='nw')
root.mainloop()
main()
20190419更新
快递100的API变动了,现在查询快递时的请求链接变成了下图中的样子,比以前多了一个参数temp,每次访问的temp都不一样,即使我把这次的链接拿去再次访问,只能得到其他快递的物流信息,再次访问,又是另一个快递的物流信息了。暂时还没得出解决方法。
Post Views: 424