Skip to content

Instantly share code, notes, and snippets.

@not522
Created December 25, 2013 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save not522/8125036 to your computer and use it in GitHub Desktop.
Save not522/8125036 to your computer and use it in GitHub Desktop.
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