Forked from ranveeraggarwal/acm20151amrita-rankscrape.py
Last active
August 29, 2015 14:07
-
-
Save adich23/5d3e845b63a55ff8280f 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 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