Yoink: https://www.javascripttutorial.net/web-apis/javascript-formdata/ customized for https://www.accessdata.fda.gov/scripts/cder/daf/index.cfm
const btn = document.querySelector('.col-sm-offset-2 > button:nth-child(1)');
const form = document.querySelector('div.panel-body:nth-child(1) > form:nth-child(1)');
btn.addEventListener('click', (e) => {
// prevent the form from submitting
// or uncomment the debugger statment below for a breakpoint
// if needing to also send the data for testing
e.preventDefault();
// show the form values
const formData = new FormData(form);
const values = [...formData.entries()];
console.log(values);
// comment out the preventDefault and uncomment below to sue breakpoints instead
// debugger;
});
// Results in:
// [
// [
// "rptname",
// "2"
// ],
// [
// "reportSelectMonth",
// "10"
// ],
// [
// "reportSelectYear",
// "2023"
// ]
// ]
let form = new FormData();
form.append("rptname", "2")
form.append("reportSelectMonth", "10")
form.append("reportSelectYear", "2023")
const request = new XMLHttpRequest();
request.open("POST", "https://www.accessdata.fda.gov/scripts/cder/daf/index.cfm?event=reportsSearch.process")
request.send(form)
Copy as cURL:
curl 'https://www.accessdata.fda.gov/scripts/cder/daf/index.cfm?event=reportsSearch.process' \
--compressed \
-X POST \
-H 'Accept-Encoding: gzip, deflate, br' \
-H 'Content-Type: multipart/form-data; boundary=---------------------------17168440862677627000709725407' \
-H 'Connection: keep-alive' \
-H 'TE: trailers' \
--data-binary $'-----------------------------17168440862677627000709725407\r\nContent-Disposition: form-data; name="rptname"\r\n\r\n2\r\n-----------------------------17168440862677627000709725407\r\nContent-Disposition: form-data; name="reportSelectMonth"\r\n\r\n10\r\n-----------------------------17168440862677627000709725407\r\nContent-Disposition: form-data; name="reportSelectYear"\r\n\r\n2023\r\n-----------------------------17168440862677627000709725407--\r\n'