Created
December 2, 2017 17:15
-
-
Save erasmo-marin/99a61e6a8d99d5d55b3c069cede5eb03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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