我已经设法让matlab登录到Google趋势来下载csv数据。首先,我使用了DownloadString,然后在使用fastawrite保存csv文件之前将其转换为matlab字符串。调用WebClient.DownloadFile时,Matlab登录和下载失败
但是,即使字符串被正确下载,'\ n'行正在失去一些格式化...这是非常奇怪的,因为如果我通过'\ n'将文件分割成单元格数组,格式化是好的!
所以我现在试图让DownloadFile方法来工作,但我不断收到以下错误:
无方法“DownloadFile”与发现类“System.Net.WebClient”
匹配签名千恩万谢,
这里的功能:
NET.addAssembly('System.Net');
url = 'https://www.google.com/accounts/ClientLogin?accountType=GOOGLE&Email=email&Passwd=pass&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));
assignin('base','googleWebClient',client);
end
saveFilePath = System.String(strcat('C:\Dropbox\PROJECTS\', keyWord, '.csv'));
data = client.DownloadFile(durl, saveFilePath);
非常感谢!我一直在禁止我的头靠在墙上....我删除了data =,它正在下载csv文件。看来,当我使用char(数据)函数从System.String转换为matlab char,然后使用fastawrite进行保存时,它以某种方式损坏了格式。 – user1229124 2012-02-23 21:45:36
对不起,regexprep(sid)格式很好,我使用的是DownloadString而不是DownloadFile,出于某种原因,有一些格式错误进入了csv文件中。 – user1229124 2012-02-23 21:51:22