標籤: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 實現快遞查詢