我在php中使用cURL google搜索Scrap

时间:2015-03-19 09:22:20

标签: php

$q = str_replace(" ", "+", $query);

    $useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0";
    $ch = curl_init ("");
    curl_setopt ($ch, CURLOPT_URL, "http://www.google.com/search?hl=en&tbo=d&site=&source=hp&q=".$q);
    curl_setopt ($ch, CURLOPT_USERAGENT, $useragent); // set user agent
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    echo $output = curl_exec ($ch);die;
    curl_close($ch);

我无法从google html获得结果。结果javascript。感谢

1 个答案:

答案 0 :(得分:0)

谷歌有一些严格的检查,这是我的查询链接,它在http://aiddroid.com上正常工作

$url = "https://www.google.dk/search?&q=".urlencode($query)."&hl=zh-CN&tbs={$tbs}&prmd={$prmd}&ei={$ei}&start=$start&sa=N";

enter image description here