javascript - PhantomJS- open page with LocalStorage by default -
i'm using phantomjs generated source of web page after javascript dom manipulations have taken place. web page has <body>
, nothing else.
important: web page uses browser's localstorage
generate page.
i want change localstorage in phantomjs before opening page.
app.js:
var page = require('webpage').create(); page.open("https://sample.com") settimeout(function(){ // want save page.render("screenshoot.png") // can access content using jquery var fbcomments = page.evaluate(function(){ return $("body").contents().find(".content") }) phantom.exit(); }, 1000)
localstorage particular domain available when open page on domain. can
- open url on domain you're interested in,
- change
localstorage
according needs, - open target url on same domain.
this can this:
page.open("https://sample.com/asdfasdf", function(){ page.evaluate(function(){ localstorage.setitem("something", "whatever"); }); page.open("https://sample.com", function(){ settimeout(function(){ // want save page.render("screenshoot.png") // can access content using jquery var fbcomments = page.evaluate(function(){ return $("body").contents().find(".content") }) phantom.exit(); },1000) }); });
it's possible not open full page in step 1. can use dummy page url.
page.setcontent("", "https://sample.com"); // doesn't open page page.evaluate(function(){ localstorage.setitem("something", "whatever"); }); page.open("https://sample.com", function(){ settimeout(function(){ // want save page.render("screenshoot.png") // can access content using jquery var fbcomments = page.evaluate(function(){ return $("body").contents().find(".content") }) phantom.exit(); }, 1000) });
Comments
Post a Comment