Last active
December 12, 2015 04:49
-
-
Save caferrari/4717185 to your computer and use it in GitHub Desktop.
Carregar funcionários do tocantins
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
<?php | |
$pages = 554; | |
$data = array(); | |
$doc = new DOMDocument; | |
libxml_use_internal_errors(true); | |
for ($page = 1; $page <= $pages; $page++){ | |
echo "Carregando página: $page" . PHP_EOL; | |
$body = file_get_contents("http://transparencia.to.gov.br/pessoal/?opt=3&n=&o=&p={$page}"); | |
$body = utf8_encode(utf8_decode($body)); | |
$doc->loadHTML($body); | |
$xpath = new DOMXPath($doc); | |
$entries = $xpath->query("//table[@class='pessoal']/tr"); | |
foreach ($entries as $entry) { | |
$cols = $entry->getElementsByTagName('td'); | |
$row = array(); | |
foreach ($cols as $col) { | |
$row[] = utf8_encode($col->nodeValue); | |
} | |
if (!count($row)) continue; | |
$data[] = $row; | |
} | |
} | |
file_put_contents(__DIR__ . '/funcionarios.json', json_encode($data)); | |
echo "Done" . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment