How can I retrieve data (csv-file) from a web database using webwrite and websave?
8 次查看(过去 30 天)
显示 更早的评论
Dear All,
I am trying to automatically retrieve data from a web database.
I came across the functions webwrite and websave and wonder whether this could work?
I basically want the code to enter four values into the web form, press submit (URL) and then
download a csv-file containing the results (URLresult).
I am looking for answers to the following questions:
- Do I need to enter an api key? If so, how can I find out what to enter (I am using Matlab R2022a
on Windows 10 )?
- How can I download the data automatically? Unfortunately, the filename of the csv-file (that is
provided after the search has been completed on the URLresult page) appears to include a random
number just before the file extension (at least when downloaded manually), so the exact filename
cannot be predicted..
Any help on this is greatly appreciated!
Best,
Luis
code example:
URL = 'https://www.accessdata.fda.gov/scripts/cdrh/cfdocs/cfMAUDE/Search.cfm';
URLresult='https://www.accessdata.fda.gov/scripts/cdrh/cfdocs/cfMAUDE/results.cfm';
writeApiKey = 'Your Write API Key'; % necessary? how can I find out?
PostName1='Manufacturer'; %names according to html
PostValue1='Siemens'; %values=text that should be entered into respective field
PostName2='BrandName';
PostValue2='Dimension';
PostName3='ReportDateFrom';
PostValue3='08/22/2018';
PostName4='ReportDateTo';
PostValue4='08/24/2022';
PostName5='Search';
PostValue5='Search';
response = webwrite(URL,'api_key',writeApiKey,...
PostName1,PostValue1,PostName2,PostValue2,PostName3,PostValue3,PostName4,PostValue4,PostName5,PostValue5);
resulttable=strcat('maudeExcelReport',num2str(randomNumber),'.csv'); %any way to find out random number or ignore part of filename?
file=websave(resulttable,URLresult);
0 个评论
回答(1 个)
Naman Kaushik
2023-6-21
Hi Luis,
I understand that you want to retrievedata programmatically from a web database.
Yes, you would require an API key for fetching the data.
Once you obtain your A.P.I.key, you can use the "webwrite" function in MATLAB, which is used to create a 'POST' request to the web. You need to specify the URL, parameters,and the authorization headers (which would include your A.P.I.key) while making the request.
You can request for an API key for the website that you are looking to access data from using the following link:
For more information on the "webwrite" function,you can refer to the following documentation:
The documentation of the required APIcan be found here:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Web Services 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!