Skip to content

Instantly share code, notes, and snippets.

@kylehill
Created October 6, 2012 16:37
Show Gist options
  • Select an option

  • Save kylehill/3845414 to your computer and use it in GitHub Desktop.

Select an option

Save kylehill/3845414 to your computer and use it in GitHub Desktop.
538 screen scraping code
var states=[];
jQuery(".eg2012-538-state-projections-container.eg2012-president").each(function(){
var state = {};
var raw_name = jQuery(this).find("h2").text().trim();
state.name = raw_name.split('\n')[2].trim();
var data_row = jQuery(this).find(".moe").parent().parent();
var raw_moe = jQuery(data_row).find(".moe").text();
state.moe = parseFloat(raw_moe.substr(1));
state.dem = parseFloat(jQuery(data_row).find(".dem").text());
state.rep = parseFloat(jQuery(data_row).find(".rep").text());
states.push(state);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment