Доброе утро! Проблема с парсингом сайта http://altei.ru/. Блокирует доступ к товарам-в переменные попадает фраза - "Unauthorized access". Пользуюсь библиотекой cUrl со всеми прибамбасами, но эффекта 0..
Ну, а мы тут при чем? Все телепаты в отпуске. У меня все норм. Код (PHP): $curl=curl_init('http://altei.ru/main/knizhki_dlya_malyishki'); $setopt=array( CURLOPT_RETURNTRANSFER=>1, CURLOPT_FOLLOWLOCATION=>1, CURLOPT_SSL_VERIFYPEER=>0 ); foreach($setopt as $const => $int) { curl_setopt($curl,$const,$int); } $html=curl_exec($curl); libxml_use_internal_errors(true); $dom=new DOMDocument('1.0','utf-8'); $dom->loadHTML($html); $xpath=new DomXPath($dom); $xquery=$xpath->query('//*[contains(@class,"list_book")]'); print_r($xquery->item(0));
Код (Text): // функция парсинга $ch = curl_init(); // параметры подключения curl_setopt($ch, CURLOPT_REFERER, 'http://google.com'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERAGENT, "Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.9.168 Version/11.51"); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 0); curl_setopt($ch, CURLOPT_COOKIEFILE,'cookies.txt'); curl_setopt($ch, CURLOPT_COOKIEJAR,'cookies.txt'); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 40000); $res=curl_exec($ch); // передача содержание страницы в переменную $html = new simple_html_dom(); $html->load($res); $div=$html->find("div[class='content']"); preg_match_all("/(?<=>)[^<>]+(?=<)/",$div[0],$div); $div=array_filter($div[0],"filter"); $div=array_values($div); Вот мой код. Спасибо за пост - буду пробывать Добавлено спустя 24 минуты 49 секунд: Эту страницу удается парсить без проблем. Не получается открыть страницы именно с товаром, например как: http://www.altei.ru/main/knizhki_dlya_malyishki/ves_nov_god
Код (PHP): $curl=curl_init('http://www.altei.ru/main/knizhki_dlya_malyishki/ves_nov_god'); $setopt=array( CURLOPT_RETURNTRANSFER=>1, CURLOPT_FOLLOWLOCATION=>1, CURLOPT_SSL_VERIFYPEER=>0 ); foreach($setopt as $const => $int) { curl_setopt($curl,$const,$int); } $html=curl_exec($curl); libxml_use_internal_errors(true); $dom=new DOMDocument('1.0','utf-8'); $dom->loadHTML($html); $xpath=new DomXPath($dom); $xquery=$xpath->query('//*[contains(@class,"content")]'); print_r($xquery->item(0)); No problems!