Python 實現快遞查詢

來源:互聯網
上載者:User

標籤:src   \n   break   快遞   amp   class   width   img   pytho   

實現效果:

原始碼:

import urllib.requestimport jsonimport msvcrtkd_dict = {1:‘shentong‘,2:‘youzhengguonei‘,3:‘yuantong‘,4:‘shunfeng‘,5:‘yunda‘,6:‘zhongtong‘,7:"tiantian",8:"debang"}def Check():    while True:        print("僅支援以下快遞公司查詢:")        print("1.申通    ")        print("2.EMS郵政    ")        print("3.圓通    ")        print("4.順風    ")        print("5.韻達    ")        print("6.中通    ")        print("7.天天    ")        print("8.德邦    ")        print("0.退出\n")        choose = int(input("請選擇您的快遞公司:"))        while choose not in range(0,6):            choose = int(input("抱歉暫不支援此公司請重新選擇:"))        if choose == 0:            print("感謝使用!\n")            break        kd_num = input("請輸入快遞單號:")        url = "http://www.kuaidi100.com/query?type=%s&postid=%s" % (kd_dict[choose], kd_num)        response = urllib.request.urlopen(url)        html = response.read().decode(‘utf-8‘)        target = json.loads(html)        #print(target)        status = target[‘status‘]        if status == ‘200‘:            data = target[‘data‘]            #print(data)            data_len = len(data)            #print(data_len)            #print("\n")            for i in range(data_len):                print("\n時間: " + data[i][‘time‘])                print("狀態: " + data[i][‘context‘] + "")            print("\n感謝使用!\n")            break        else:            print("輸入有誤請重新輸入!\n")    #print("按任意鍵結束......")if __name__ == ‘__main__‘:    while True:        Check()        out = input("按任一數字退出(其他鍵繼續).........")        if out >= ‘0‘ and out <= ‘9‘:            break        else:            print("\n")            continue            

 

-----------------------

無聊............ 

Python 實現快遞查詢

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.