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
17
18
19
20
21
22
23
24
25
26
27
28
29
// import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
import process from "node:process";
export const browserlessScrapeExample = (async () => {
try {
const res = await fetch(
`https://chrome.browserless.io/scrape?token=${process.env.browserlessKey}`,
{
method: "POST",
headers: {
"Cache-Control": "no-cache",
"Content-Type": "application/json",
},
body: JSON.stringify({
"url": "https://www.zaobao.com/realtime",
"elements": [{
"selector": "body",
}],
}),
},
);
// For this request, Browserless returns one data item
const data = await res.json();
console.log(data);
return data.data[0].results[0].html;
} catch (err) {
console.log(err);
}
})();
baj-browserlessscrapeexample.web.val.run
November 9, 2023