I Just Want To Read Text From URL And Save It As Txt.... But How?
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello, Community
I just want to ask about how to read text data from URL and save it as ASCII / .Txt Data. It maybe a simple question for all of you, but it kinda so difficult for me...
So i have a data from URL like this :
2024 05 21 33744 33744.5 2602 4 1.667 1.000 1.000 2.667 2.667 2.333 1.667 1.667 6 4 4 12 12 9 6 6 7 165 190.8 195.4 0 2024 05 22 33745 33745.5 2602 5 1.667 0.667 0.333 0.333 0.000 0.667 1.333 1.333 6 3 2 2 0 3 5 5 3 152 195.7 200.6 0 2024 05 23 33746 33746.5 2602 6 0.667 1.667 1.667 2.333 2.333 1.667 2.333 4.000 3 6 6 9 9 6 9 27 9 134 176.2 180.7 0 2024 05 24 33747 33747.5 2602 7 2.000 3.000 2.667 3.000 2.000 1.333 0.333 1.333 7 15 12 15 7 5 2 5 8 126 162.8 167.0 0 2024 05 25 33748 33748.5 2602 8 1.667 1.333 1.333 0.667 0.667 1.667 1.333 2.333 6 5 5 3 3 6 5 9 5 104 152.4 156.4 0 2024 05 26 33749 33749.5 2602 9 1.333 2.333 1.000 2.000 2.667 2.667 2.667 1.000 5 9 4 7 12 12 12 4 8 120 155.6 159.7 0
Or like this in the image of the source:
The data result of webread function is just like this :
textweb = webread("https://kp.gfz-potsdam.de/kpdata?startdate=2024-05-21&enddate=2024-05-26&format=kp1#kpdatadownload-143");
textweb =
'2024 05 21 33744 33744.5 2602 4 1.667 1.000 1.000 2.667 2.667 2.333 1.667 1.667 6 4 4 12 12 9 6 6 7 165 190.8 195.4 0
2024 05 22 33745 33745.5 2602 5 1.667 0.667 0.333 0.333 0.000 0.667 1.333 1.333 6 3 2 2 0 3 5 5 3 152 195.7 200.6 0
2024 05 23 33746 33746.5 2602 6 0.667 1.667 1.667 2.333 2.333 1.667 2.333 4.000 3 6 6 9 9 6 9 27 9 134 176.2 180.7 0
2024 05 24 33747 33747.5 2602 7 2.000 3.000 2.667 3.000 2.000 1.333 0.333 1.333 7 15 12 15 7 5 2 5 8 126 162.8 167.0 0
2024 05 25 33748 33748.5 2602 8 1.667 1.333 1.333 0.667 0.667 1.667 1.333 2.333 6 5 5 3 3 6 5 9 5 104 152.4 156.4 0
2024 05 26 33749 33749.5 2602 9 1.333 2.333 1.000 2.000 2.667 2.667 2.667 1.000 5 9 4 7 12 12 12 4 8 120 155.6 159.7 0
'
And i want to know how to convert the output of webread function above to become a data like this :
"2024 05 21 33744 33744.5 2602 4 1.667 1.000 1.000 2.667 2.667 2.333 1.667 1.667 6 4 4 12 12 9 6 6 7 165 190.8 195.4 0"
"2024 05 22 33745 33745.5 2602 5 1.667 0.667 0.333 0.333 0.000 0.667 1.333 1.333 6 3 2 2 0 3 5 5 3 152 195.7 200.6 0"
"2024 05 23 33746 33746.5 2602 6 0.667 1.667 1.667 2.333 2.333 1.667 2.333 4.000 3 6 6 9 9 6 9 27 9 134 176.2 180.7 0"
"2024 05 24 33747 33747.5 2602 7 2.000 3.000 2.667 3.000 2.000 1.333 0.333 1.333 7 15 12 15 7 5 2 5 8 126 162.8 167.0 0"
"2024 05 25 33748 33748.5 2602 8 1.667 1.333 1.333 0.667 0.667 1.667 1.333 2.333 6 5 5 3 3 6 5 9 5 104 152.4 156.4 0"
"2024 05 26 33749 33749.5 2602 9 1.333 2.333 1.000 2.000 2.667 2.667 2.667 1.000 5 9 4 7 12 12 12 4 8 120 155.6 159.7 0"
OR just simply save the output of webread function to become a txt file (ASCII) which can be opened in my local PC...
Thank you everyone for your attention and cooperation. I would be very grateful if community can help me to solve this problem /.\ /.\ /.\
댓글 수: 0
채택된 답변
Mathieu NOE
2024년 5월 27일
hello
try this
textweb = webread("https://kp.gfz-potsdam.de/kpdata?startdate=2024-05-21&enddate=2024-05-26&format=kp1#kpdatadownload-143");
% save char array to txt file :
filename = 'myTextFile.txt';
% Open the file for writing using fopen:
fid = fopen(filename, 'w'); % Open the file for writing (overwrite if necessary)
% Write the char array to the file using fprintf. In this case, we interpret newline characters as new lines:
fprintf(fid, '%s', textweb);
% Close the file using fclose (this step is important!):
fclose(fid);
댓글 수: 6
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Export에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!