Created
October 11, 2014 18:35
-
-
Save ranveeraggarwal/ac541fdbf80179db9336 to your computer and use it in GitHub Desktop.
ACM ICPC 2015 - Round I - Amritapuri - Rank List Scraper
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 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
Dependencies: BeautifulSoup