Created
February 12, 2014 11:36
-
-
Save livemark/8953954 to your computer and use it in GitHub Desktop.
Loading HTML element from cURL DOMXPatch
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
| $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