Last active
August 29, 2015 14:18
-
-
Save jclapp23/6e712dfae01e82391656 to your computer and use it in GitHub Desktop.
Phantom JS scrape populations by state
This file contains 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
private function scrapePopulationsByState(){ | |
$cssSelector = "table.sk_popcharttable"; | |
$siteUrl = "http://www.ipl.org/div/stateknow/popchart.html"; | |
$tableXmlObject = pullXmlObjBlogExample($siteUrl,$cssSelector); | |
$cnt = 0; | |
foreach($tableXmlObject->tbody->tr as $tableRow){ | |
//the first two rows are the header and "All United States" rows so disregard | |
if($cnt++ < 2) | |
continue; | |
//grab the state and population from the corresponding table cell of the row and output! | |
$state = (string) $tableRow->td[1]->a; | |
$population = (string) $tableRow->td[2]; | |
echo $state . " has a population of " . $population . "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment