Skip to content

Instantly share code, notes, and snippets.

@pedropuppim
Last active March 27, 2024 13:58
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 pedropuppim/82d7671d22731b5f522269c295977a38 to your computer and use it in GitHub Desktop.
Save pedropuppim/82d7671d22731b5f522269c295977a38 to your computer and use it in GitHub Desktop.
Cidades aderentes a NFSE nacional
<?php
$url = 'https://www.gov.br/nfse/pt-br/municipios/municipios-aderentes/municipios-aderentes';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$html = curl_exec($ch);
curl_close($ch);
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$query = "//table//tr[td[contains(text(), 'Conveniado e Ativo')]]";
$rows = $xpath->query($query);
$cities = [];
foreach ($rows as $row) {
if ($row->childNodes->item(9)->nodeValue == "Conveniado e Ativo") {
$cities[] = $row->childNodes->item(3)->nodeValue . " - " . $row->childNodes->item(5)->nodeValue;
}
}
echo "<pre>";
print_r($cities);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment