在调用 WebClient.DownloadFile以尝试直接从 matlab 下载 csv 中的谷歌趋势数据时,我一直在使用Matlab 登录和下载失败中发布的原始代码。
我还在 Emanuele 在login with curl 和 get session 中阅读了 Google 的身份验证策略已更改的帖子,现在我的代码如下所示:
NET.addAssembly('System.Net');
url = strcat(['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');
client.Headers.Add('Cookies', char(sid(1)));
client.Headers.Add('Authorization', strcat( 'GoogleLogin ' , char(sid(3)) ) );
end
client.DownloadString(durl)
无情地返回:
ans =
<div id="report">
<div class="timeBandTitle">An error has been detected</div>
<div class="timeBandSubTitle">You have reached your quota limit. Please try again later.</div>
</div>
如果有人能够从 matlab 访问谷歌趋势 csv 数据,你就是我的英雄