Python Common script Query Express

Source: Internet
Author: User

Learn while you are practicing. Use Python to query for Express.

# coding:utf-8 ' Created on March 16, 2018 afternoon 12:12:52} @author: CHW ' ' Import requests as Req Import JSON import sys def
    Getexpress (company, Code): "' Funcation:get Express infomation 2 args Company:the Express Company code 
    
    Code:the Express Bill code ' URL = ' http://www.kuaidi100.com/query?type={}&postid={} '. Format (company, code) Response = req.get (URL) if Response.status_code!= 200:print (' query failed.
        {} '. Format (response.status_code)) return None def parse (text): Jsonobj = json.loads (text) 
        Print (' {} {} '). Format (' Current state: ', Jsonobj.get (' message ')) ' status = Jsonobj.get (' status ') # Get Status code (200 is normal) If status = = ': For x in Jsonobj.get (' data '): Print ('%s '% (x.get) (' time '), X.G ET (' context ')) Parse (response.text) def qureycomcode (mailno): Urlpara = ' http:// www.kuaidi100.com/autonumber/autocomnum?resultv2=1&text={} ' Paga = Req.get (Urlpara.format (mailno)) Jsonobj = Json.loads (Paga.text.decode (' UTF8 ')) if Paga.status_ Code!= 200:return None for item in Jsonobj.get (' Auto '): Return Item.get (' Comcode ') ret Urn None if __name__ = = ' __main__ ': Mailno = ' 813422761260 ' Comcode = Qureycomcode (mailno) if comcod    E is None:print (' {} '. Format (' query failed ')) Sys.exit () getexpress (Comcode, Mailno)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.