Skip to content

Instantly share code, notes, and snippets.

@evan-brass
Last active June 8, 2025 15:54
Show Gist options
  • Save evan-brass/17a793da2fc935994099196beb36d8ae to your computer and use it in GitHub Desktop.
Save evan-brass/17a793da2fc935994099196beb36d8ae to your computer and use it in GitHub Desktop.
Example of using a CORS proxy to fetch data from a website.
const data = new FormData();
// I don't know what these values should be...
data.set('txtIDnummer', '123#567');
data.set('txtChipNr', '');
data.set('ddlLan', '');
data.set('txtOrt', '');
data.set('ddlKon', '');
// Send a post request
const request = await fetch('https://corsproxy.io/?' + encodeURIComponent('https://hundar.skk.se/agarreg/katt_sok.aspx'), {
method: 'POST',
headers: {
// Sometimes APIs let you request data in a specific format, though I don't think this page supports that.
// accept: 'text/JSON'
},
body: data,
});
console.log(request);
if (!request.ok) throw new Error(`uh oh ${request.statusText}`, { cause: request });
// Parse the response HTML page into a document:
const html_text = await request.text();
const doc = new DOMParser().parseFromString(html_text, 'text/html');
console.log(doc);
// Pull the response rows out of that document:
// TODO: Use a CSS selector that pulls out the HTML elements containing the returned results.
const results = Array.from(doc.body.querySelectorAll("tr"), el => el.innerHTML);
console.log(results);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment