Skip to content

Instantly share code, notes, and snippets.

@livemark
Created February 12, 2014 11:36
Show Gist options
  • Select an option

  • Save livemark/8953954 to your computer and use it in GitHub Desktop.

Select an option

Save livemark/8953954 to your computer and use it in GitHub Desktop.
Loading HTML element from cURL DOMXPatch
$curl = curl_init('http://www.agenciaic.com.br/icomm-agencia-de-marketing-digital-em-sao-paulo/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$page = curl_exec($curl);
if(curl_errno($curl)):
echo 'Erro: ' . curl_error($curl);
exit;
endif;
curl_close($curl);
$DOM = new DOMDocument;
libxml_use_internal_errors(true);
if(!$DOM->loadHTML($page)):
$erros = null;
foreach (libxml_get_errors() as $error):
$errors.= $error->message."\r\n";
endforeach;
libxml_clear_errors();
print "LibXML Erros: \r\n$erros";
return;
endif;
$Xpath = new DOMXPath($DOM);
$content = $Xpath->query('//*[@class="content"]')->item(0);
echo utf8_decode($content->textContent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment