PhantomJS create page from string

后端 未结 5 1410
忘掉有多难
忘掉有多难 2020-12-08 04:21

Is it possible to create a page from a string?

example:

html = \'blah blah blah\'

page.open(html,         


        
5条回答
  •  余生分开走
    2020-12-08 04:54

    I got the following to work in PhantomJS version 2.0.0. Whereas before, I was using page.open() to open a page from the filesystem and set a callback:

    page.open("bench.html", pageLoadCallback);
    

    Now, I accomplish the same thing from a string variable with the HTML page. The page.setContent() method requires a URL as the second argument, and this uses fs.absolute() to construct a file:// URL.

    page.onLoadFinished = pageLoadCallback;
    page.setContent(bench_str, "file://" + fs.absolute(".") + "/bench.html");
    

提交回复
热议问题