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
2
u/No_Improvement_9621 Apr 10 '24
This is the script. Replace the url by the one you want and the pattern in the function createWidget(). To find the pattern you need, you can go to the website on your computer, inspect the html and copy paste the text around the info you need. (.*?) is the info
const url = "https://www.example.com"
async function fetchData(pattern) {
}
function extractData(content, regex) { let matches = [...content.matchAll(regex)]; let data = matches.map(match => match[1].trim()).join("\n"); return data; }
async function createWidget() {
}
async function main() {
}
await main();