Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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