abhilash
abhilash

Reputation: 11

download and display the google trends csv file using php

i been trying to download the csv file from this link http://www.google.com/trends/trendsReport?hl=en-US&q=nba&geo=US&date=today%207-d&cmpt=q&content=1&export=1

but failed again and again, i tried most of the codes available online and here on stackexchange also, but none got me working properly, if anyone know how to achieve it, please share it here, as most of us get it useful.

i also got some advice that it uses cookies these days. another advice is one should use the google account to login and then try, but unfortunately i failed both.

or else i may be going wrong. the one valid trial i did was here.

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ClientLogin?accountType=GOOGLE&[email protected]&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;
?>

Upvotes: 0

Views: 2096

Answers (1)

Kaustubh Kendurkar
Kaustubh Kendurkar

Reputation: 139

Use file_get_contents , I don't think their is need to use curl .

for example

$page = file_get_contents('http://www.example.com/');
echo $page;

Upvotes: 1

Related Questions