【问题标题】:file_get_contents & curl returns empty string for google trendsfile_get_contents 和 curl 返回谷歌趋势的空字符串
【发布时间】:2016-01-27 18:54:45
【问题描述】:

我尝试获取此网址的内容

http://www.google.com/trends/fetchComponent?q=ex%20machina&cid=TIMESERIES_GRAPH_0&export=3

使用 file_get_contents 和 curl 但它什么也不返回,但是当我直接转到链接时,它会显示内容,因此它不是 api 限制等问题。

它工作过一次,但在随后的调用之后就不行了

这是我使用的 curl 方法

 function get_data($url) {
        $ch = curl_init();
        //$timeout = 5;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    } 

【问题讨论】:

  • 如何使用get_data?如果我使用 'echo get_data("URL_HERE");' 对我来说效果很好
  • file_get_contents(url) 为我工作

标签: php curl file-get-contents


【解决方案1】:

我在使用 Google Maps Geocoder API 和 file_get_contents 时遇到了类似的问题,您可以在此处找到解决方案:

Google Maps Geocode API only works via browser

试试这个网址: http://www.google.com/trends/fetchComponent?q=ex+machina&cid=TIMESERIES_GRAPH_0&export=3

【讨论】:

    猜你喜欢
    • 2011-05-09
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    • 1970-01-01
    • 2015-01-24
    • 2015-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多