0

我一直在尝试从此链接下载 csv 文件 http://www.google.com/trends/trendsReport?hl=en-US&q=nba&geo=US&date=today%207-d&cmpt=q&content=1&export=1

但是一次又一次地失败了,我尝试了大多数在线和 stackexchange 上可用的代码,但没有一个能让我正常工作,如果有人知道如何实现它,请在这里分享,因为我们大多数人都觉得它有用。

我也得到了一些建议,这些天它使用 cookie。另一个建议是应该使用谷歌帐户登录然后尝试,但不幸的是我都失败了。

否则我可能会出错。我做的一个有效的试验是在这里。

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ClientLogin?accountType=GOOGLE&Email=myemail@gmail.com&Passwd=mypass&service=trends&source=test-test-v1");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_MAXREDIRS, 20);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_COOKIEJAR, '/var/www/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/var/www/cookies.txt');

$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_setopt($ch, CURLOPT_URL, "http://www.google.com/trends/explore#q=nba&geo=US&date=today%207-d&cmpt=q");
$output = curl_exec($ch);
curl_close($ch);
echo $output;
?>
4

1 回答 1

1

使用 file_get_contents ,我认为他们不需要使用 curl 。

例如

$page = file_get_contents('http://www.example.com/');
echo $page;
于 2013-01-15T09:25:41.533 回答