- # coding: utf-8
- # file: simple_search.py
- # date: 2014-08-24
- # author: John
- """
- 快递速查。
- """
- import urllib, urllib2
- from json import loads
- def getExpress(raw_url, exp_type, exp_id):
- try:
- tail = urllib.urlencode({"type":exp_type, "postid":exp_id})
- real_url = raw_url + "?" + tail
- req = urllib2.Request(real_url)
- f = urllib2.urlopen(req)
- data = f.read()
- return loads(data)["data"]
- except urllib2.URLError, e:
- pass
- except KeyError, e:
- pass
- finally:
- try: f.close()
- except NameError, e: pass
- return None
- url = r"http://www.kuaidi100.com/query"
- exp_type = raw_input(u'快递类型(拼音,如"shunfeng"):'.encode("gbk"))
- exp_id = raw_input(u'货运号:'.encode("gbk"))
- data = getExpress(url, exp_type, exp_id)
- for item in data:
- print item[u"time"],
- print item[u"context"]
- input()
- #该片段来自于http://www.codesnippet.cn/detail/2608201410335.html
来源: http://www.codesnippet.cn/detail/2608201410335.html