PhantomJS create page from string

后端 未结 5 1393
忘掉有多难
忘掉有多难 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

    Looking at the phantomjs API, page.open requires a URL as the first argument, not an HTML string. This is why the what you tried does not work.

    However, one way that you might be able to achieve the effect of creating a page from a string is to host an empty "skeleton page," somewhere with a URL (could be localhost), and then include Javascript (using includeJs) into the empty page. The Javascript that you include into the blank page can use document.write("

    blah blah blah

    ") to dynamically add content to the webpage.

    I've ever done this, but AFAIK this should work.

    Sample skeleton page:

    
    
    
    
    
    

提交回复
热议问题