Skip to content

Instantly share code, notes, and snippets.

@stiles
Created April 30, 2012 23:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save stiles/2563588 to your computer and use it in GitHub Desktop.
Scrape NFL
#!/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