Last active
May 17, 2017 07:03
-
-
Save jasonliao/5260257293284b8dccc127fd5f9c2d0f to your computer and use it in GitHub Desktop.
phantomjs capture lazy load page
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
var page = require('webpage').create() | |
var config = { | |
screen_width: 650, | |
screen_height: 1334, | |
user_agent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1 UTest/1.0.0', | |
resource_wait: 500, | |
scroll_distance: 600, | |
url: 'https://gist.github.com', | |
screenshot_name: 'gist.png' | |
} | |
page.viewportSize = { width: config.screen_width, height: config.screen_height } | |
page.settings.userAgent = config.user_agent | |
page.open(config.url, function() { | |
var pageHeight = page.evaluate(function() { | |
return document.body.clientHeight | |
}) | |
var top = 0 | |
var t = setInterval(function() { | |
if (top < pageHeight) { | |
top += config.scroll_distance | |
page.scrollPosition = { top: top, left: 0 } | |
} else { | |
page.scrollPosition = { top: 0, left: 0 } | |
page.render(config.screenshot_name) | |
phantom.exit() | |
clearInterval(t) | |
} | |
}, config.resource_wait) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
capture page with touch gesture (without scrollbar)
.my-page-content
.my-page
17 is scrollbar width