PHP调用GOGLE API实现GOOGLE查询

类别:编程语言 点击:0 评论:0 推荐:

<?php

//需求:

//http://www.phpclass.org下载一个GoogleSearch.php的类文件

//Get the NuSOAP library (http://dietrich.ganx4.com/nusoap)

//Register with Google to receive an authentication key. You can

//register online at http://www.google.com/apis/.

require_once 'GoogleSearch.php';

$gs = new GoogleSearch();

$gs->setKey("vzpQePxQFHKyvGhEnuvEJGVF********");//此处填入你自己的GOOGLE KEY

$gs->setQueryString("battery"); //set query string to search.

$gs->setStartResult(10);

$gs->setMaxResults(10);  //set max. number of results to be returned.

$gs->setSafeSearch(true);   //set Google "SafeSearch" feature.

$search_result = $gs->doSearch();

echo "Document Filtering: " . $search_result->getDocumentFiltering() . "<br>";

echo "Search Comments: " . $search_result->getSearchComments() . "<br>";

echo "EstimatedTotalResultsCount: " . $search_result->getEstimatedTotalResultsCount() . "<br>";

echo "Is Estimate Exact: " . $search_result->getEstimateIsExact() . "<br>";

echo "Search Query: " . $search_result->getSearchQuery() . "<br>";

echo "Start Index: " . $search_result->getStartIndex() . "<br>";

echo "End Index: " . $search_result->getEndIndex() . "<br>";

echo "Search Tips: " . $search_result->getSearchTips() . "<br>";

echo "Search Time: " . $search_result->getSearchTime() . "<br>";

$re = $search_result->getResultElements();

 

foreach($re as $element)

{

    echo "<p>";

    echo "<br>Title: " . $element->getTitle();

    echo " URL: " . $element->getURL();

    echo "<br>Snippet: " . $element->getSnippet();

    echo "<br>Summary: " . $element->getSummary();

    echo "<br>Host Name: " . $element->getHostName();

    echo " Related Information Present?: " . $element->getRelatedInformationPresent();

    echo " Cached Size: " . $element->getCachedSize();

    echo "<br>Directory Title: " . $element->getDirectoryTitle();

 

    $dircat = $element->getDirectoryCategory();

 

    echo "<br>Full Viewable Name: " . $dircat->getFullViewableName();

    echo " Special Encoding: " . $dircat->getSpecialEncoding();

}

?>

本文地址:http://com.8s8s.com/it/it28053.htm