Skip to content

Instantly share code, notes, and snippets.

@huksley
Created November 21, 2021 07:50
Show Gist options
  • Save huksley/81213fc562f2ae1fd787fcb8006185d9 to your computer and use it in GitHub Desktop.
Save huksley/81213fc562f2ae1fd787fcb8006185d9 to your computer and use it in GitHub Desktop.
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const userAgent =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:89.0) Gecko/20100101 Firefox/89.0";
const cookieJar = new jsdom.CookieJar();
const resources = new jsdom.ResourceLoader({
userAgent
});
const defs = {
referrer: "https://google.com",
includeNodeLocations: true,
storageQuota: 10000000,
pretendToBeVisual: true,
cookieJar,
resources
};
JSDOM.fromURL("https://google.com", defs).then(dom => {
const document = dom.window.document;
const nodes = Array.from(document.querySelectorAll("div"));
console.info(nodes);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment