Open Live Writer 代码插入插件测试
1 #-*-coding:utf-8-*- 2 import urllib 3 import json 4 import sys 5 import ssl 6 ssl._create_default_https_context = ssl._create_unverified_context 7 8 def gettype(number):#定义取快递类型函数 9 def getlist():#取快递类型列表 10 req = urllib.urlopen('http://www.kuaidi100.com/autonumber/autoComNum?text=%d' %number) 11 html = req.read() 12 dict_html = json.loads(html) 13 return dict_html['auto'] 14 for i in getlist(): 15 type = i['comCode'] 16 return type 17 18 def getprocess(url):#定义获取快递进度函数 19 req = urllib.urlopen(url) 20 html = req.read() 21 #type = sys.getfilesystemencoding() #取文件系统编码类型 22 #html = html.decode('utf-8').encode(type) #utf-8解码 由于解码后和json里面解码冲突,故注释掉此段代码 23 dict_info =json.loads(html) 24 return dict_info['data'] 25 26 27 28 number= input(u"请输入快递单号:") 29 30 type = gettype(number)#获取快递类型 31 32 33 Address = 'http://www.kuaidi100.com/query?type=%s&postid=%d&id=1&valicode=&temp=0.33020057185034335' %(type,number) 34 for i in getprocess(Address): 35 print i['ftime'] + i['context']
测试一下,代码功能为查快递。