Script to download xml files from a website

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
Walter Roberson 2017년 7월 3일
편집: John Kelly 2017년 7월 12일

2 개 추천

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
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
Walter Roberson 2017년 6월 5일

1 개 추천

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.

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

태그

질문:

2017년 6월 4일

편집:

2017년 7월 12일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by