4.01.2011

JavaScript is the scourge of the universe

I want to win my fantasy baseball league, but I think ESPN's interface leaves something to be desired. I want to take the daily stats from my team and put it into a more useful format. Sadly, the hardest part is getting the data.

ESPN doesn't want any of the raw statistics to get out, I suppose for good reason. However, I really just want a daily feed of how each player performed, points-wise. ESPN has a simple web page to handle this, which it terms the 'quick box score'. Even better, these box scores aren't protected by the authentication interface that the rest of the fantasy baseball functions are behind, so you can just query a pretty straight-forward URL and get the quick box score for any day of scoring. The first day of play (yesterday) is day 1, and ESPN simply increments that paramater in the URL each day. These box scores contain nicely formatted tables with all the data I want, as shown.

Sadly, however, these pages are not generated by the server. Instead, some sort of AJAX query is used to generate them in the browser. Unfortunately, the code that underpins ESPN's site is as ugly as the site itself. Looking at the source reveals piles of indecipherable JavaScript to generate the tables. This is a problem because any automated method of fetching a box score won't be able to parse the JavaScript. Thus, none of the important data will ever load.

And that's pretty much where I gave up. I know I can have my script open the page in a GUI web browser, then save the resulting static page back out and have the script continue working, but that amount of interactivity is too much. I really wanted the script to handle this for me, running the stats once a day and generating the report I want. I will work on this more eventually, but for now I just don't want to have to deal with all of these terrible web issues. Unless someone else has a suggestion for parsing the JavaScript, I'll leave this alone for a few days.

No comments:

Post a Comment