前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python制作快递查询系统

Python制作快递查询系统

作者头像
Yuyy
发布2022-06-28 18:46:12
8840
发布2022-06-28 18:46:12
举报
文章被收录于专栏:yuyy.info技术专栏

本文最后更新于 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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-4-19 1,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 20190419更新
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档