Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 简单的HTML Dom抓取Google结果_Php_Html_Xml_Dom_Web Scraping - Fatal编程技术网

Php 简单的HTML Dom抓取Google结果

Php 简单的HTML Dom抓取Google结果,php,html,xml,dom,web-scraping,Php,Html,Xml,Dom,Web Scraping,我需要刮去谷歌返回任何查询的一小段文本,作为知识图结果的一部分——通常位于右边的一段,它从维基百科获得。这样我就可以将纯文本转换为语音应答。使用简单的HTMLDOM,我可以从Bing或Ask中抓取这些信息,但是这个结果嵌套在Google上的DIV和SPAN中,我无法得到它。简单功能如下: $question = str_replace(' ','+',$_GET['question']); $address = 'http://www.google.co.uk/search?q='.$quest

我需要刮去谷歌返回任何查询的一小段文本,作为知识图结果的一部分——通常位于右边的一段,它从维基百科获得。这样我就可以将纯文本转换为语音应答。使用简单的HTMLDOM,我可以从Bing或Ask中抓取这些信息,但是这个结果嵌套在Google上的DIV和SPAN中,我无法得到它。简单功能如下:

$question = str_replace(' ','+',$_GET['question']);
$address = 'http://www.google.co.uk/search?q='.$question;
$ret = scraping_Google($address);

function scraping_Google($url) {
    // create HTML DOM
    $html = file_get_html($url);

    // get title
    $ret = $html->find('div.kno-rdesc', 0)->plaintext;

    // clean up memory
    $html->clear();
    unset($html);

    return $ret;
}

echo $ret;

正是div.kno-rdesc是内容嵌套的地方,我可以使用Chrome上的代码检查器轻松检索到它。然而,解析这一小块信息却没有成功。有人能帮忙吗?干杯

你不需要刮它。谷歌有一个API