Scrape NFL
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
#!/usr/bin/env python | |
from mechanize import Browser | |
from BeautifulSoup import BeautifulSoup | |
import urllib | |
import urllib2 | |
import csv | |
for year in range(1936, 2012): | |
mech = Browser() | |
url = "http://www.nfl.com/draft/history/fulldraft?season="+str(year) | |
page = urllib2.urlopen(url) | |
html = page.read() | |
soup = BeautifulSoup(html) | |
table = soup.find("table", {'class': 'data-table1'}) | |
for row in table.findAll('tr')[1:]: | |
col = row.findAll('td') | |
selection = col[0].text | |
team = col[1].text | |
player = col[2].text | |
position = col[3].text | |
school = col[4].text | |
season = str(year) | |
draftround = "First" | |
record = (selection, team, player, position, school, season, draftround) | |
print "|".join(record) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment