Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { fetch } from "https://esm.town/v/std/fetch";
export let getBodyFromURL = async (url) => {
const { DOMParser } = await import(
"https://deno.land/x/deno_dom/deno-dom-wasm.ts"
);
// Fetch HTML from the specified URL
const response = await fetch(url);
const html = await response.text();
// Parse the HTML into a new document
const parser = new DOMParser();
const doc = parser.parseFromString(html, "text/html");
// Get the main text content of the document
const bodyText = doc.body.textContent;
return bodyText;
};
October 23, 2023