Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在phantomjs中将字符串设置为网页的响应_Phantomjs - Fatal编程技术网

在phantomjs中将字符串设置为网页的响应

在phantomjs中将字符串设置为网页的响应,phantomjs,Phantomjs,嗨,我想做的是不要把网页作为 page.open(url); 但要设置已检索为页面响应的字符串。可以这样做吗?是的,它和分配给page.content一样简单。通常还值得设置page.url(否则,如果使用Ajax、SSE等进行任何操作,您可能会遇到跨域问题),而setContent函数有助于一次性完成这两个步骤。以下是一个基本示例: var page = require('webpage').create(); page.setContent("<html><head>

嗨,我想做的是不要把网页作为

page.open(url);

但要设置已检索为页面响应的字符串。可以这样做吗?

是的,它和分配给page.content一样简单。通常还值得设置page.url(否则,如果使用Ajax、SSE等进行任何操作,您可能会遇到跨域问题),而
setContent
函数有助于一次性完成这两个步骤。以下是一个基本示例:

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();
var page=require('webpage').create();
page.setContent(“body{background:#fff;text:#000;}Test#1Test#1Something

”,”http://localhost/imaginary/file1.html"); console.log(page.plainText); page.render(“test.png”); phantom.exit();

因此,使用您已有的“先前检索到的页面响应”调用page.setContent。

Thnx,这非常有用。