How to get Google Indexed pages count via PHP

前端 未结 1 1556
说谎
说谎 2021-01-28 21:38

Hello I am trying to create a script that should retrieve a count with all indexed pages from Google. Only the count of total pages (the results from site:$domain)

I fou

相关标签:
1条回答
  • 2021-01-28 22:15

    Try This:

    <?php
    function getpageindexed($name){
    $weburl="http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:".$name."&filter=0";
    $ch=curl_init();
    curl_setopt($ch, CURLOPT_URL, $weburl);
    curl_setopt($ch, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt ($ch, CURLOPT_HEADER, 0);
    curl_setopt ($ch, CURLOPT_NOBODY, 0);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    $json = curl_exec($ch);
    curl_close($ch);
    $data=json_decode($json,true);
    if($data['responseStatus']==200)
    return $data['responseData']['cursor']['resultCount'];
    else
    return false;
    }
    
    $name="domainname.com"; //your domain name
    echo getpageindexed($name); //get indexed page
    ?>
    
    0 讨论(0)
提交回复
热议问题