I have a script tag inside my page but it isn't being run. It is simply rendered.
I have the following code:
var phantom = require('phantom');
phantom.create(function(ph,error) {
c = callback;
ph.createPage(function( page,err ) {
page.setContent( output );
callback = c;
setTimeout(function() {
page.evaluate(function() {
return document.getElementsByTagName('html')[0].innerHTML;
}, function(html) {
callback(html);
});
}, 5000);
});
});
How do I tell phantom to "load"/"execute" the page so that the script on the page runs? (I don't want to use page.open)
Also, content is "<p>Page <strong>1</strong> content.</p><button id=\"page1_button\">button</button><script>document.getElementsByTagName('p').innerHTML = 'test';</script>"
Call page.open, see http://phantomjs.org/api/webpage for arguments.
The first argument is a url, the second one is a callback.
In the callback to page.open you should then call page.evaluate as you previously tried.
page.open("http://httpbin.org/get", function(status) {
if (status == "success") {
page.evaluate(function() {
// ...
});
}
});