Created
December 25, 2013 17:18
-
-
Save not522/8125036 to your computer and use it in GitHub Desktop.
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
import mechanize | |
import socket | |
import sys | |
import urllib2 | |
from HTMLParser import HTMLParser | |
rd = | |
pm = | |
cr = | |
user_name = '' | |
password = '' | |
class MyHTMLParser(HTMLParser): | |
flag = bool() | |
def handle_starttag(self, tag, attrs): | |
if len(attrs) > 0 and len(attrs[0]) > 1 and attrs[0][1] == 'statHighlight': | |
self.flag = True | |
if tag == 'a': | |
self.flag = False | |
def handle_endtag(self, tag): | |
if tag == 'td': | |
self.flag = False | |
def handle_data(self, data): | |
data = data.strip() | |
if self.flag and len(data) > 0: | |
data = data.split('.')[0] | |
print int(data) | |
for i in range(1, 3000, 8): | |
print >> sys.stderr, str(i) | |
base_uri = 'http://community.topcoder.com/longcontest/stats/?module=ViewSystemTestResults' | |
uri = base_uri + '&rd=' + str(rd) + '&pm=' + str(pm) + '&cr=' + str(cr) + '&stc=' + str(i) | |
while True: | |
try: | |
br = mechanize.Browser() | |
br.open(uri) | |
br.select_form(name='frmLogin') | |
br['ha'] = user_name | |
br['pass'] = password | |
res = br.submit() | |
html = res.read() | |
parser = MyHTMLParser() | |
parser.feed(html) | |
sys.stdout.flush() | |
break | |
except (urllib2.URLError, socket.timeout): | |
continue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment