Last active
October 19, 2017 02:15
-
-
Save zhangyuan/e9ef7bcf9264ce7df08f9cf9d5ed4790 to your computer and use it in GitHub Desktop.
Save web page to PDF with selenium and 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
// npm install selenium-webdriver phantomjs-prebuilt --save | |
const webdriver = require('selenium-webdriver') | |
async function render(driver, filename) { | |
return await driver.executePhantomJS(`this.render("${filename}")`); | |
} | |
const main = async () => { | |
const customPhantom = webdriver.Capabilities.phantomjs(); | |
const driver = new webdriver.Builder() | |
.withCapabilities(customPhantom) | |
.build() | |
await driver.manage().window().setSize(1200, 300); | |
await driver.get('https://github.com') | |
await render(driver, './page.pdf'); | |
driver.quit(); | |
}; | |
(async () => { | |
await main(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment