Skip to content

Instantly share code, notes, and snippets.

@benz2012
Last active October 4, 2017 20:57
Show Gist options
  • Save benz2012/391684ed097df2862a09e2981f96ebba to your computer and use it in GitHub Desktop.
Save benz2012/391684ed097df2862a09e2981f96ebba to your computer and use it in GitHub Desktop.
Node.js Scraper for Client Rendered HTML
const phantom = require('phantom')
const clientRenderedHtml = (url, callback) => {
let _ph, _page, _content
phantom.create().then(ph => {
_ph = ph
return _ph.createPage()
}).then(page => {
_page = page
return _page.property('viewportSize', { width: 1920 })
}).then(() => {
return _page.open(url)
}).then(status => {
console.log(`Phantom status: ${status}`)
return _page.property('content')
}).then(content => {
_content = content
return _page.close()
}).then(() => {
return _ph.exit()
}).then(() => {
callback(null, _content)
})
.catch(err => callback(err, null))
}
module.exports = clientRenderedHtml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment