2010-12-04 88 views
-1

IM使用此代碼:如何從php的api獲取所有的谷歌搜索結果?

function doGoogleSearch($searchTerm) 
    { 
    //$cx="002000009380213215808:hf9v-g9oyho";   
    $endpoint = 'web'; 
    $key= 'XXX'; 
    $url = "http://ajax.googleapis.com/ajax/services/search/".$endpoint; 

    $args['q'] = $searchTerm; 
    $args['v'] = '1.0'; 

    $url .= '?'.http_build_query($args, '', '&'); 

    $ch = curl_init()or die("Cannot init"); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);   
    $body = curl_exec($ch)or die("cannot execute"); 
    curl_close($ch); 
    //decode and return the response 
    return json_decode($body,1); 
    } 

利用這一點,我剛剛從it.Is第1個'4結果有什麼辦法讓谷歌的整個搜索結果?

回答

0

正如指出in the Google Web Search API Class Reference可以使用rsz = 8得到8個結果的時間和start = xxx改變「頁」的結果(即獲得下一組8)

有沒有辦法讓更多的每次超過8個結果,返回結果的最大數量爲64個(請參閱說明here,並再次輸入in the Class Reference)。

此外,Web Search API已棄用,您應該使用Custom Search API來代替。

+0

哦,它的工作well.but如何使用從這裏開始?會像這樣開始= XXX? – 2010-12-04 08:49:08