Created
October 6, 2012 16:37
-
-
Save kylehill/3845414 to your computer and use it in GitHub Desktop.
538 screen scraping code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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