2012-02-23 2 views
1

Google Trends에 로그인하여 csv 데이터를 다운로드하려면 matlab을 사용할 수 있습니다. 먼저 DownloadString을 사용한 다음 fastawrite를 사용하여 csv 파일을 저장하기 전에 matlab 문자열로 변환했습니다.WebClient.DownloadFile을 호출 할 때 Matlab 로그인 및 다운로드 오류가 발생했습니다.

비록 문자열이 올바르게 다운로드되었다고해도 '\ n'줄은 형식을 잃어 버렸습니다 ... '\ n'파일을 셀 배열로 분할하면 서식이 잘되므로 ! 그래서

는 지금 작동하려면 DownloadFile 방법을 얻으려고하지만 나는 다음과 같은 오류가 계속 :

'System.Net.WebClient'

클래스 발견 일치하는 서명이 없음 방법 없다 'DownloadFile'
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); 

답변

0

이 형식의 어떤 종류의

을 잃은되고있다 :

많은 감사, 여기에

함수입니까? 유닉스 모드 (\ n)의 텍스트를 가져온 다음 DOS 모드 (\ r \ n) 편집기에서 열어 보는 것 같습니다. 빠른 regexprep(sid, '\r?\n', sprintf('\r\n'))으로 해결할 수 있습니다. 아마 DownloadFile로 전환하지 않을 것입니다.

"아무 것도 없습니다"오류가 발생하는 한 WebClient.DownloadFile에는 void 반환 형식이 있습니다. Matlab의 .NET 지원은 서명의 일부분을 고려한 것처럼 보입니다. "data ="할당을 제거하면됩니다.

>> client = System.Net.WebClient; 
>> x = client.DownloadFile('http://www.cnn.com', 'C:\temp\blah.html') 
No method 'DownloadFile' with matching signature found for class 'System.Net.WebClient'. 

>> client.DownloadFile('http://www.cnn.com', 'C:\temp\blah.html') 
>> 
+0

정말 고마워요 !! 나는 벽에 머리를 대고있다. 나는 데이터를 삭제했다. 그리고 그것은 csv 파일을 그대로 다운로드하고있다. 그것은 내가 char (data) 함수를 사용하여 System.String에서 matlab char로 변환 한 다음 fastawrite를 사용하여 저장하면 포맷팅이 손상되었다고 생각됩니다. – user1229124

+0

죄송합니다. regexprep (sid) 형식이 좋으며 DownloadFile과 반대로 DownloadString을 사용하고 있었으며 어떤 이유로 포맷 오류가 CSV 파일에 들어 왔습니다 ... – user1229124

관련 문제