Skip to content

Instantly share code, notes, and snippets.

@erasmo-marin
Created December 2, 2017 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erasmo-marin/99a61e6a8d99d5d55b3c069cede5eb03 to your computer and use it in GitHub Desktop.
Save erasmo-marin/99a61e6a8d99d5d55b3c069cede5eb03 to your computer and use it in GitHub Desktop.
import puppeteer from "puppeteer";
async function crawler({ url, browser }) {
let page = null;
let html = false;
try {
page = await browser.newPage();
//networkidle0: consider navigation to be finished when
//there are no more than 2 network connections for at least 500 ms.
//(https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagegobackoptions)
await page.goto(url, { waitUntil: "networkidle0" });
html = await page.content();
} catch (e) {
debug.warn(`Not able to fetch ${url}`);
} finally {
if (page) {
await page.close();
}
return html;
}
}
export default crawler;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment