Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save adich23/5d3e845b63a55ff8280f to your computer and use it in GitHub Desktop.
Save adich23/5d3e845b63a55ff8280f to your computer and use it in GitHub Desktop.
import urllib2
from bs4 import BeautifulSoup
page = urllib2.urlopen('http://www.codechef.com/rankings/ACMAMR14?utm_content=bufferd975d&utm_medium=social&utm_source=facebook.com&utm_campaign=buffer')
page = page.read()
soup = BeautifulSoup(page)
soup.prettify()
userranks = []
for anchor in soup.findAll('a', href=True):
p = anchor['href']
if "users/acm14am" in p:
userranks.append(p.strip("/users"))
i = 1
for arank in userranks:
teampage = urllib2.urlopen('http://www.codechef.com/teams/view/'+arank).read()
teamsoup = BeautifulSoup(teampage)
teamsoup.prettify()
tables = teamsoup.find_all("table", {"cellpadding":"0", "cellspacing":"0", "border":"0"})
need = tables[1]
res = need.find_all("td")
needer = str(i) + " , " + res[3].get_text() + " , " + res[13].get_text()
print(needer.encode('utf-8'))
i = i+1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment