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.