Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: cookies/authorisation to access google trends csv
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Adam Chapman

Posts: 171
Registered: 1/12/09
cookies/authorisation to access google trends csv
Posted: Jun 6, 2013 12:00 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I'm trying to download a csv of google trend data, as was done at http://stackoverflow.com/questions/9419444/matlab-login-and-download-failure-when-calling-webclient-downloadfile in February 2012.

My existing code looks like this:




%--------------------------------------------------------------

keyWord='mickey mouse'
USERNAME='username'
PASWORD=password


NET.addAssembly('System.Net');

url = ['https://www.google.com/accounts/ClientLogin?accountType=GOOGLE&Email=' USERNAME '&Passwd=' PASSWORD '&service=trendspro&source=test-test-v1';
durl = System.String(strcat('http://www.google.com/trends/viz?q=', keyWord, '&date=all&geo=all&graph=all_csv&sort=0&scale=1&sa=N'));

if exist('googleWebClient','var')
client = googleWebClient;
else
client = System.Net.WebClient;

response = client.DownloadString(url);
sid = char(response.ToString);
sid = regexp(sid, '\n', 'split'); %sid = sid(1,1);

client.Headers.Add('Cookie', char(sid(1)));

end

saveFilePath = System.String(strcat('C:\Dropbox\PROJECTS\', keyWord, '.csv'))


client.DownloadFile(durl,'trendtest.csv');


%--------------------------------------------------------------------




If anybody runs this they will see that the returned csv file contains nothing useful.



I have found something that may be a bit sompler to access:
view-source:http://www.google.com/trends/fetchComponent?q=mickey%20mouse&cid=TIMESERIES_GRAPH_0&export=3&date=today%203-m&cmpt=q

although I think this wants some authentication data for access.





I did notice in the original code above that the variable "response" contains 3 pieces of information (SID, LSID & AUTH)


Is anybody able to access either a csv or json formatted data from matlab alone?
Both urls are accessible through any web browser I've used, but matlab is struggling.

Any help is massively appreciated



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.