Reading data from a different URL each iteration

1 次查看(过去 30 天)
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 App Building 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by