function index() { //Create object of Simple_html_dom class $html = new Simple_html_dom(); //use Simple_html_dom class function load_file $html->load_file('http://www.google.com'); //use Simple_html_dom class function find foreach ($html->find('img') as $element) { echo $element->src . '<br>'; } }
/** * getCaptchaToken() * @return boolean/Array */ private function getCaptchaToken() { $ch = curl_init('http://www.receita.fazenda.gov.br/pessoajuridica/cnpj/cnpjreva/Cnpjreva_Solicitacao2.asp?cnpj='); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookieFile); $htmlResult = curl_exec($ch); if (!$htmlResult) { return false; } $html = new Simple_html_dom($htmlResult); $url_imagem = $tokenValue = ''; $imgcaptcha = $html->find('img[id=imgcaptcha]'); if (count($imgcaptcha)) { foreach ($imgcaptcha as $imgAttr) { $url_imagem = $imgAttr->src; } if (preg_match('#guid=(.*)$#', $url_imagem, $arr)) { $idCaptcha = $arr[1]; $viewstate = $html->find('input[id=viewstate]'); if (count($viewstate)) { foreach ($viewstate as $inputViewstate) { $tokenValue = $inputViewstate->value; } } if (!empty($idCaptcha) && !empty($tokenValue)) { return array($idCaptcha, $tokenValue); } else { return false; } } } }