Created
March 27, 2012 08:54
-
-
Save HansMayer/2214131 to your computer and use it in GitHub Desktop.
A simple script in python to print tracking informations from China EMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# A python script to grab China EMS. | |
import urllib, urllib2, cookielib, re | |
TRACKINGID='RAxxxxxxCN' | |
def getURL(url,post=None,headers=[]): | |
cj = cookielib.LWPCookieJar() | |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) | |
opener.addheaders = [('User-Agent', 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2;)'),('Accept-Charset','utf-8')]+headers | |
usock=opener.open(url,post) | |
response=usock.read() | |
usock.close() | |
return unicode(response, 'utf-8',errors='strict') | |
r = re.compile("<tr bgcolor=\".*?\">.*?<td>(.*?)</td>.*?<td>(.*?)</td>.*?<td>(.*?)</td>.*?<td>(.*?)</td>.*?<td>(.*?)</td>.*?<td>(.*?)</td>.*?</tr>",re.DOTALL) | |
html = getURL('http://intmail.183.com.cn/item/batch/itemBatchQuery.do', post='isTrace=no&itemNo1='+TRACKINGID, headers=[("Origin",'http://intmail.183.com.cn'),('Referer','http://intmail.183.com.cn/item/batch/itemBatchQuery.do')]) | |
for track in r.findall(html): | |
print 'Tracking ID: '+track[0].strip()[:-6] | |
print 'Year: '+track[1].strip()[:-6] | |
print 'Status: '+track[2].strip()[:-6] | |
print 'Destination country: '+track[3].strip()[:-6] | |
print 'Current location: '+track[4].strip()[:-6] | |
print 'Last updated: '+track[5].strip()[:-6] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment