Skip to content

Instantly share code, notes, and snippets.

@ranveeraggarwal
Created October 11, 2014 18:35
Show Gist options
  • Save ranveeraggarwal/ac541fdbf80179db9336 to your computer and use it in GitHub Desktop.
Save ranveeraggarwal/ac541fdbf80179db9336 to your computer and use it in GitHub Desktop.
ACM ICPC 2015 - Round I - Amritapuri - Rank List Scraper
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
@ranveeraggarwal
Copy link
Author

Dependencies: BeautifulSoup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment