Last active
October 4, 2017 20:57
-
-
Save benz2012/391684ed097df2862a09e2981f96ebba to your computer and use it in GitHub Desktop.
Node.js Scraper for Client Rendered HTML
This file contains hidden or 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') | |
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