Script to download xml files from a website
8 ビュー (過去 30 日間)
古いコメントを表示
I would like to write a script that download xml files from
https://www.treasurydirect.gov/xml/
with the file name that starts from R_ and put into a single excel file. Please advise.
回答 (2 件)
Walter Roberson
2017 年 7 月 3 日
編集済み: John Kelly
2017 年 7 月 12 日
MATLAB Answers is not a private consulting service. The "cost" we charge for providing answers is that the posted Questions and Answers are public so that everyone can learn from them. Editing away your question after you have received your answer is rude.
If you want to ask questions without the question and answer becoming public, then you should hire a private consultant.
1 件のコメント
Adam
2017 年 7 月 5 日
It's a shame we can't have a system for flagging users who keep doing this so we know not to waste time answering their questions in future. I know we can search every person's history of questions before answering, but obviously that isn't something anyone wants to do.
Walter Roberson
2017 年 6 月 5 日
base = 'https://www.treasurydirect.gov/xml/'
S = urlread(base);
R_files = regexp(S,'(?<=<a href=")R[^"]+', 'match');
num_files = length(R_files);
R_content = cell(num_files, 1);
for K = 1 : num_files
try
R_content{K} = urlread( [base, R_files{K}] );
end
end
fid = fopen('YourOutput.csv', 'wt');
for K = 1 : num_files
fwrite(fid, regexprep(R_content{K}, {'^', '$'}, {'"', '"'}, 'lineanchors') );
end
fclose(fid)
My Magic 8 Ball predicts disappointment in the CSV file created: it predicts that you want to extract particular data from each of the files and write those as columns, instead of what you asked for, which is to write the content of .xml files directly as lines in the csv.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!