我已經設法讓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