php file_get_contents 函数获取google的页面 是不是获取不到!
有3个 简体,英文,繁体,
英文和繁体都可以获得到,但简体获不到,求解,是不是就是获取不到.

解决方案 »

  1.   

    是不行
     $content=file_get_contents(" http://www.google.com.hk/search?hl=zh-CN&source=hp&q=%E4%BD%A0%E5%A5%BD&aq=f&aqi=&aql=&oq=&gs_rfai=");
               echo $content;
    这个是简体的 echo 结果是 空 $content=file_get_contents(" http://www.google.com.hk/search?hl=en&source=hp&q=%E4%BD%A0%E5%A5%BD&aq=f&aqi=&aql=&oq=&gs_rfai=");
               echo $content;这个是英文的,可以搜索出来.
    帮帮看下,按理应该可以的
      

  2.   

    我刚看了下~~可能是那边做了google那边做了限制!
      

  3.   

    中文简体返回的http头:HTTP/1.1 302 Found
    Location: http://www.google.com.hk/url?sa=p&hl=zh-CN&cki=PREF%3DID%3D53459f08f6f9007c:FF%3D1:LD%3Dzh-CN:TM%3D1291704487:LM%3D1291704487:S%3Ded6MOnyGNhAbpi7P&q=http://www.google.com.hk/search%3Fhl%3Dzh-CN%26source%3Dhp%26biw%3D1440%26bih%3D690%26q%3Dfsdf%26btnG%3DGoogle%2B%25E6%2590%259C%25E7%25B4%25A2%26aq%3Df%26aqi%3D%26aql%3D%26oq%3D%26gs_rfai%3D&ust=1291704517933326&usg=AFQjCNG2hivRvEbZbYMFgb6J9-qd_WtVbA
    Cache-Control: private
    Content-Type: text/html; charset=UTF-8
    Set-Cookie: PREF=ID=53459f08f6f9007c:FF=0:TM=1291704487:LM=1291704487:S=X7W5uBA19OgWikzu; expires=Thu, 06-Dec-2012 06:48:07 GMT; path=/; domain=.google.com.hk
    Date: Tue, 07 Dec 2010 06:48:07 GMT
    Server: gws
    Content-Length: 617
    X-XSS-Protection: 1; mode=block
    Connection: close
      

  4.   

    重定向的问题,好解决吗  curl这个函数 具体不怎么会用
      

  5.   

    curl抓取的结果应该也是空的!
      

  6.   


    $dd="http://www.google.com.hk/search?q=你好&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:zh-CN:official&client=firefox-a";
    $content=file_get_contents($dd);
    echo $content;
      

  7.   

    我用了 curl  和 snoopy 都不行。
    google对来路请求是否是从浏览器地址中进行的,进行了判断。
    伪装浏览器
    伪造来路皆不行。
      

  8.   

    用cURL,可以修改header中的Referer
      

  9.   

    还要启用cookie,并将cookie值原封不动地反馈给google.
      

  10.   

    有的网站有重定向或者防火墙最好用curl或者snoopy
      

  11.   

    curl 也还找不到,怎么模仿呢
      

  12.   

    楼上说的curl的方法我没试过是否可行,
    不过curl确实可以更改发送的http头!你查下手册就知道了
      

  13.   

     <?
    header("Content-type:text/html;Charset=utf-8");    // 1. 初始化
    $url = "http://www.google.com.hk/custom?hl=zh-CN&inlang=zh-CN&newwindow=1&safe=strict&cof=AH%3Aleft%3BL%3Ahttp%3A%2F%2Fwww.chinaz.com%2FIMAGES%2Flogo.gif%3BLH%3A60%3BLW%3A165%3BLBGC%3Awhite%3BVLC%3A%23551A8B%3BALC%3A%23ff3300%3BGFNT%3A%237777CC%3BGIMP%3A%23FF0000%3BDIV%3A%23000099%3B&domains=chinaz.com&q=%E4%BD%A0%E5%A5%BD&btnG=Google+%E6%90%9C%E7%B4%A2&sitesearch=&meta=";
    $ch = curl_init();
    // 2. 设置选项,包括URL
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_HTTPHEADER,array(
         "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; TheWorld)",
             "Accept-Language: en"
    ));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    // 3. 执行并获取HTML文档内容
    $output = curl_exec($ch);
    // 4. 释放curl句柄
    curl_close($ch);
    echo iconv("gbk","utf-8",$output);
    ?> 
      

  14.   

    楼上的代码 得到的也是 301 moved
      

  15.   

    这个代码已经测试成功了:
    <?php
    header("Content-Type: text/html;charset=utf-8");
    $url = "http://www.google.com.hk/search?hl=zh-CN&source=hp&q=%E4%BD%A0%E5%A5%BD&btnG=Google+%E6%90%9C%E7%B4%A2&meta=lr%3Dlang_zh-CN&aq=f&aqi=&aql=&oq=&gs_rfai=";
    //echo urldecode($url);
    $cookie_file = dirname(__FILE__)."/temp/google.txt";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
    $contents = curl_exec($ch);
    curl_close($ch);
    echo $contents ;
    ?>
    四点注意:
    一:google用的是utf-8编码
    二:GET的数据需要用urlencode()进行编码
    三:必须模拟浏览器
    四:必须存储cookie
    你给的分也太少了,下次多给些分啊。
      

  16.   

    运行上面这个代码之前 需在本文件夹里建temp文件夹,并在temp里建google.txt 
    否则执行会出错!
      

  17.   


    大哥  要是服务器不支持CURLOPT_FOLLOWLOCATION怎么办啊... 我也遇到这个问题