517
517
url = 'http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&P_COD_UNI=%(number)s'
518
518
def _parse_page(self, html):
519
html = html.decode('utf-8', 'ignore')
520
res = re.findall(r'<td rowspan=1>(.*?)</td><td>(.*?)</td><td><FONT COLOR=".*?">(.*?)</font></td>',
521
html, re.DOTALL|re.IGNORECASE)
522
return [ (op, parsedate(date, dayfirst=True), ' '.join(post.split())) for (date, post, op) in res]
519
html = html.decode('ISO-8859-1', 'ignore')
520
res = re.findall(r'<tr><td rowspan=.*?>(.*?)</td><td>(.*?)</td><td><FONT COLOR=".*?">(.*?)</font></td></tr>(?:\s*?<tr><td colspan=2>(.*?)</td></tr>)?',
521
html, re.DOTALL|re.IGNORECASE|re.UNICODE)
523
for (date, post, op, obs) in res:
524
resdate = parsedate(date, dayfirst=True)
525
respost = u' '.join(post.split())
527
resop = u' '.join(op.split() + [u'-'] + obs.split())
529
resop = u' '.join(op.split())
530
result.append((resop, resdate, respost))
524
533
if __name__ == '__main__':
525
534
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
537
546
#service = UkrposhtaComService('RB041697087UA')
538
547
#service = DhlDeService('129921786448')
539
548
#service = UpsComService('1Z882E910397601345')
540
service = CorreiosComService('RQ867951061BR')
549
service = CorreiosComService('RD024810847SE')
541
550
for i in service.fetch():
542
551
print u'\t'.join([unicode(j) for j in i])