Set a string as the response of a webpage in phantomjs -


hi trying not webpage as

page.open(url); 

but set string has been retrieved page response. can done?

yes, , easy assigning page.content. worth setting page.url (as otherwise might hit cross-domain issues if doing ajax, sse, etc.), , setcontent function helpful both steps in 1 go. here basic example:

var page = require('webpage').create(); page.setcontent("<html><head><style>body{background:#fff;text:#000;}</style><title>test#1</title></head><body><h1>test #1</h1><p>something</p></body></html>","http://localhost/imaginary/file1.html");  console.log(page.plaintext); page.render("test.png"); phantom.exit(); 

so call page.setcontent "previously retrieved page response" have.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -