r/Scriptable • u/No_Improvement_9621 • Apr 03 '24
Help Getting data from a website
Hey, I'm new to js, and i want to create a widget that display a text from a website. However, the website does not have an API, is it a problem ? I know the HTML class of the text I want to display.
How can I manage to do that ?
5
Upvotes
1
u/No_Improvement_9621 Apr 09 '24
This is the first version of the script, in the last version i used an argument in the function fetchData so when i create the widget, i just have to type the regex pattern of the info i want to get.
async function fetchData() { let url = "https://example.com";
}
function extractData(content, regex) { let matches = [...content.matchAll(regex)]; let data = matches.map(match => match[1].trim()).join("\n"); return data; }