Last active
February 25, 2016 19:54
-
-
Save paseto/870f78dcfc16f3c7d652 to your computer and use it in GitHub Desktop.
Busca CEP Correios 2016 - PHP
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
$fo = fopen("cep.html", "w+"); | |
$url = "http://wxww.buscacep.correios.com.br/sistemas/buscacep/resultadoBuscaEndereco.cfm"; | |
$cep = "03712000"; | |
set_time_limit(0); | |
$process = curl_init(str_replace(" ", "%20", $url)); | |
curl_setopt($process, CURLOPT_HTTPHEADER, array('application/x-www-form-urlencoded')); | |
curl_setopt($process, CURLOPT_POST, TRUE); | |
curl_setopt($process, CURLOPT_POSTFIELDS, "CEP=" . $cep . ""); | |
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE); | |
$return = curl_exec($process); | |
fwrite($fo, $return); | |
$dom = new DOMDocument; | |
$dom->loadHTMLFile('cep.html'); | |
$cells = $dom->getElementsByTagName('td'); | |
foreach ($cells as $cell) { | |
echo $cell->nodeValue, PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment