Answer the question
In order to leave comments, you need to log in
How to find the number of pages in the Google index?
Hello!
How to find the number of pages in the Google index?
maybe there is some API for this?
I tried to get the page https://www.google.com/search?hl=ru&q=site:site.ru via curl and parse it, but the number of pages is displayed only in the browser, when the page is received via curl, another page with results comes (without this data)
Answer the question
In order to leave comments, you need to log in
I don't know, I checked everything works for me
<?PHP
$ch = curl_init();
$site = "https://habr.com/";
$url = "https://www.google.com/search?hl=ru&q=site:$site";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER , true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0');
$content = curl_exec($ch);
if(!$content){
echo 'Ошибка curl: ' . curl_error($ch);
die;
}
curl_close($ch);
if(preg_match("/Результатов:\s*(примерно)?\s*([^(]+)/",$content,$matches))
echo "Количество: ".$matches[2];
else
echo "Не найдено";
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question