localStorage for a particular domain is only available when you open a page on that domain. You can
- open some URL on the domain you're interested in,
- change
localStorage
according to your needs,
- open your target URL on the same domain.
This can look like this:
page.open("https://sample.com/asdfasdf", function(){
page.evaluate(function(){
localStorage.setItem("something", "whatever");
});
page.open("https://sample.com", function(){
setTimeout(function(){
// Where you want to save it
page.render("screenshoot.png")
// You can access its content using jQuery
var fbcomments = page.evaluate(function(){
return $("body").contents().find(".content")
})
phantom.exit();
},1000)
});
});
It's also possible not to open a full page in step 1. You can also use dummy page with some URL.
page.setContent("", "https://sample.com"); // doesn't actually open any page
page.evaluate(function(){
localStorage.setItem("something", "whatever");
});
page.open("https://sample.com", function(){
setTimeout(function(){
// Where you want to save it
page.render("screenshoot.png")
// You can access its content using jQuery
var fbcomments = page.evaluate(function(){
return $("body").contents().find(".content")
})
phantom.exit();
}, 1000)
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…