Тема: Парсер
Добрий день! Допоможіть мені розібратіся з парсером. Коли я намагаюсь парсити Росію http://qlaster.ru/enterprises/16-470-pticefabriki у мене парсится регіон Екатеренбург. В чому моя помилка?
function arr($url, $start, $end){
if ($start < $end) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$html = curl_exec($ch);
curl_close($ch);
$file = phpQuery::newDocument($html);
$file = pq($file);
foreach ($file->find('.kotel_block .ones_block') as $inside) {
$inside = pq($inside);
$doc = $inside->find('.ones_h1 a')->attr('href');
$ini = "https://msk.qlaster.ru";
$res = $ini."$doc";
$res."<br>";
$ss = curl_init($res);
curl_setopt($ss, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ss, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ss, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ss, CURLOPT_SSL_VERIFYPEER, false);
$htm = curl_exec($ss);
curl_close($ss);
$fil = phpQuery::newDocument($htm);
$fil = pq($fil);
$title = trim($fil->find('.portal_h1 span')->text());
echo $title;
$title = trim($fil->find('.portal_h1 span')->text());
$sfera = trim($fil->find('.portal p')->text());
$email = trim($fil->find('.sait_line:eq(3) a')->text());
$time = trim($fil->find('.sait_line:eq(7) p')->text());
$site = trim($fil->find('.sait_line:nth-child(2) a')->text());
$phone = trim($fil->find('.sait_line:nth-child(1) p')->text());
$yourlica = trim($fil->find('.sait_line:eq(4) p')->text());
$user = trim($fil->find('.sait_line:eq(6) p')->text());
$strit = trim($fil->find('.sait_right .street-address')->text());
//AddParse ($site, $phone, $yourlica, $user ,$strit, $title, $sfera, $email, $time);
xprint($title);
xprint($sfera);
xprint($email);
xprint($time);
xprint($site);
xprint($phone);
xprint($yourlica);
xprint($user);
xprint($strit);
echo '<hr>';
phpQuery::unloadDocuments($htm);
}
phpQuery::unloadDocuments($html);
$pagin = $file->find('.pagination ul li:last-child a')->attr('href');
$next = $ini."$pagin";
if (!empty($next)) {
$start++;
arr($next, $start, $end);
}
}
}
$url = "http://qlaster.ru/enterprises/16-470-pticefabriki";
$start = 0;
$end = 1;
arr($url, $start, $end);