python做查询系统_Python制作快递查询系统

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:

207

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值