Reading data from a different URL each iteration

2 ビュー (過去 30 日間)
Salma fathi
Salma fathi 2022 年 10 月 18 日
コメント済み: Salma fathi 2022 年 10 月 24 日
i am trying to read some data from a specific website, in this website there are some parametrs that we need to set to get the desired data, now reading the data for manually speccifed parametrs is an easy job. Now I am trying to automate this proceess such that the parametrs would be changed accordingly and the data for each set of parameters would be read directly without my interaction. to do that I have the follwoing URL that I am reading the data from
httpUrl = "https://lgdc.uml.edu/common/DIDBGetValues?ursiCode=JI91J&charName=foF2,foF1,foE,foEs,hmF2,hmF1,hmE" + ...
"&DMUF=3000&fromDate=1997%2F01%2F01+00%3A00%3A00&toDate=1997%2F12%2F31+11%3A59%3A00";
where the parameters that need to be changed in the URL every time are the following
fromDate=1997%2F01%2F01+00%3A00%3A00 % where we need to change the year eveery time which is here =1997
which represent the starting date of the desired data and
toDate=1997%2F12%2F31+11%3A59%3A00 % where we need to change the year eveery time which is here =1997
which represent the ending date of the desired data. I strated with the follwoing lines but I am not sure how I can make the URL change every time and store all the read data in a table at the end.
httpUrl = "https://lgdc.uml.edu/common/DIDBGetValues?ursiCode=JI91J&charName=foF2,foF1,foE,foEs,hmF2,hmF1,hmE" + ...
"&DMUF=3000&fromDate=1997%2F01%2F01+00%3A00%3A00&toDate=1997%2F12%2F31+11%3A59%3A00";
options = weboptions("ContentType", "text");
data = webread(httpUrl, options);
Iono= array2table(data);

採用された回答

Jan
Jan 2022 年 10 月 18 日
編集済み: Jan 2022 年 10 月 18 日
F = "https://lgdc.uml.edu/common/DIDBGetValues?ursiCode=JI91J&charName=foF2,foF1,foE,foEs,hmF2,hmF1,hmE" + ...
"&DMUF=3000&fromDate=%04d%%2F01%%2F01+00%%3A00%%3A00&toDate=%04d%%2F12%%2F31+11%%3A59%%3A00";
% % -> %%, then 1997 -> %04d
URL = sprintf(F, 1998, 1999)
URL = "https://lgdc.uml.edu/common/DIDBGetValues?ursiCode=JI91J&charName=foF2,foF1,foE,foEs,hmF2,hmF1,hmE&DMUF=3000&fromDate=1998%2F01%2F01+00%3A00%3A00&toDate=1999%2F12%2F31+11%3A59%3A00"
  3 件のコメント
Jan
Jan 2022 年 10 月 24 日
F = "https://lgdc.uml.edu/common/DIDBGetValues?ursiCode=%s&charName=foF2,foF1,foE,foEs,hmF2,hmF1,hmE" + ...
"&DMUF=3000&fromDate=%04d%%2F01%%2F01+00%%3A00%%3A00&toDate=%04d%%2F12%%2F31+11%%3A59%%3A00";
URL = sprintf(F, 'QQQQQQ', 1998, 1999)
URL = "https://lgdc.uml.edu/common/DIDBGetValues?ursiCode=QQQQQQ&charName=foF2,foF1,foE,foEs,hmF2,hmF1,hmE&DMUF=3000&fromDate=1998%2F01%2F01+00%3A00%3A00&toDate=1999%2F12%2F31+11%3A59%3A00"
The format %04d prints a number with 4 digits and leading zeros. %s inserts a string or CHAR vector.
You find an exhaustive explanation of the formats at:
doc sprintf
Salma fathi
Salma fathi 2022 年 10 月 24 日
Thank you so much that was so helpful.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by