Created
March 26, 2017 21:07
-
-
Save bennycode/e81f233bb6d2bae4bed4beba055c4e20 to your computer and use it in GitHub Desktop.
Get dynamic page content with PhantomJS
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
const phantom = require('phantom'); | |
/** | |
* Acts like a web browser and gets page content (also from dynamic HTML pages). | |
* @param {string} url - Page URL | |
* @returns {Promise.<string, Error>} Resolves with the page content. | |
*/ | |
module.exports = async function(url) { | |
const instance = await phantom.create(); | |
const page = await instance.createPage(); | |
await page.on('onResourceRequested', () => { | |
}); | |
await page.open(url); | |
const content = await page.property('content'); | |
await instance.exit(); | |
return content; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires
"node": ">= 7.6.0"
package.json