Skip to content

Instantly share code, notes, and snippets.

@bennycode
Created March 26, 2017 21:07
Show Gist options
  • Save bennycode/e81f233bb6d2bae4bed4beba055c4e20 to your computer and use it in GitHub Desktop.
Save bennycode/e81f233bb6d2bae4bed4beba055c4e20 to your computer and use it in GitHub Desktop.
Get dynamic page content with PhantomJS
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;
};
@bennycode
Copy link
Author

bennycode commented Mar 26, 2017

Requires "node": ">= 7.6.0"

package.json

{
  "dependencies": {
    "phantom": "4.0.x"
  },
  "engineStrict": true,
  "engines": {
    "node": ">= 7.6.0"
  },
  ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment