Fantasy Football Cheat Sheet Scraper



>> Wednesday, August 18, 2010

With my fantasy football draft coming up, I thought I would create a quick Groovy script to scrape a couple Fantasy Football cheat sheets. If you don't know, a cheat sheet has a ranking of players that you can use to make your draft picks. There are a bunch available online, and they are updated frequently (like now that Brett Favre is back with the Vikings I assume he will move up and Tarvaris Jackson will move down in rank).

Since I wanted the most up-to-date ones on the day of my draft, I wrote a couple classes in Groovy to read the webpages and print out the results in a common format. This turned out the be pretty easy to do.

For example, here is one from http://www.fftoolbox.com:


import org.cyberneko.html.parsers.SAXParser;

class FFToolbox {
public List getPlayerList(){
def playerList = []

//read the XML
['http://www.fftoolbox.com/football/2010/overall.cfm?page=1',
'http://www.fftoolbox.com/football/2010/overall.cfm?page=2',
'http://www.fftoolbox.com/football/2010/overall.cfm?page=3',
'http://www.fftoolbox.com/football/2010/overall.cfm?page=4'].each{url ->
def html = new XmlSlurper(new SAXParser()).parse(url)
def table = html.BODY.'**'.findAll{ it.name() == 'TABLE'}[0]
def rows = table.TBODY.children()[1..-2]

//convert to my BO
rows.each{ nextRow ->
def columns = nextRow.children()
playerList.add(new CheatSheetEntry(
rank: columns[0],
name: columns[1],
position: columns[2],
team: columns[3],
byeWeek: columns[4])
)
}
}
return playerList
}
}


Note that the import is from here and provides an HTML parser

Here is another example from ESPN.com:

class ESPN {
public List getPlayerList(){
def playerList = []

def url = 'http://sports.espn.go.com/fantasy/football/ffl/story?page=NFLDK2K10rankstop200'
def html = new XmlSlurper(new SAXParser()).parse(url)

def table = html.BODY.'**'.findAll{ it.name() == 'TABLE'}[0]
def rows = table.TBODY.children()

rows.each{nextRow ->
def columns = nextRow.children()
def positionMatcher = columns[3].text() =~ /\D+/
playerList.add(new CheatSheetEntry(
rank: columns[0],
name: columns[1].text().substring(0, columns[1].text().indexOf(",")),
position: positionMatcher[0],
team: columns[1].text().substring(columns[1].text().indexOf(",") + 2),
byeWeek: columns[2])
)
}

return playerList
}
}


Basically they do the same things: Connect to and parse the url(s), find the table with the cheat sheet, and then go through the rows and columns assigning the correct values to a GroovyBean called CheatSheetEntry.

Now I just need to combine the lists somehow to get an average ranking of the players.

1 comments:

fantasy football bye weeks January 30, 2014 at 9:22 AM  

These cheats are so effective. i always depend on this cheats a lot. Fantasy football is now so popular.

Post a Comment

  © Blogger template Webnolia by Ourblogtemplates.com 2009

Back to TOP