Skip to content

Instantly share code, notes, and snippets.

@jclapp23
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jclapp23/6e712dfae01e82391656 to your computer and use it in GitHub Desktop.
Save jclapp23/6e712dfae01e82391656 to your computer and use it in GitHub Desktop.
Phantom JS scrape populations by state
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