0

I want to manually set the content of my "page". I do not want to load it from an url. My html, which I set contains a script-file which creates links. Now I want to execute this script, and get the dynamically generated link.

If I load the page from an url, it's no problem. But If I want to set the content manually the script-file is not executed I think!

var page  = require('webpage').create();
var system = require('system');

// Build page
var content = '<script type="text/javascript" src="script-which-creates-links.js"></script>';
page.content = content;

// Evaluate and get links
var links = page.evaluate(function() {

  var currentDocument = document;

  ......

  return currentDocument.documentElement.innerHTML;

});

system.stderr.write(links);

phantom.exit();

The output is:

<script type="text/javascript" src="script-which-creates-links.js"></script>

But I hoped I get something like that:

<script type="text/javascript" src="script-which-creates-links.js"></script>
<!-- Dynamically generated: -->
<a href="#">Link1</a>

How to tell phantomJS to execute the script-files?

EDIT: If I change the var content line to:

var content = '<script type="text/javascript">document.write("HALLO");</script>';

The script is successfully executed.

rakete
  • 2,953
  • 11
  • 54
  • 108
  • Where is *script-which-creates-links.js* located? – Artjom B. Feb 21 '16 at 13:14
  • On another webserver.. for example: http://test.de/script-which-creates-links.js – rakete Feb 21 '16 at 13:37
  • Possible duplicate of [External CSS not taken into account on PhantomJS page](http://stackoverflow.com/questions/34004835/external-css-not-taken-into-account-on-phantomjs-page) – Artjom B. Feb 21 '16 at 13:53

0 Answers0