jarrod817
12/12/2015 - 3:51 AM

Web Analytics Class - Open ESPN website and export ranking of college football teams

Web Analytics Class - Open ESPN website and export ranking of college football teams


from bs4 import BeautifulSoup 
import urllib2 
import sys
import csv
import os


os.getcwd()
os.chdir("C:\\Users\\Jarrod\\Desktop")
f = csv.writer(open("CollegeRecord2.csv","w"))

soup = BeautifulSoup(urllib2.urlopen("http://espn.go.com/college-football/powerrankings").read())
result = soup.findAll('table',{'class':"tablehead"})

for row in result[0].findAll('tr'):
    tds = row.findAll('td')
    if (len(tds)==1):
        print str(tds[0].get_text())
    else:
        a = str(tds[0].string)
        b = str(tds[1].get_text())
        f.writerow([a,b])