I have the following code, when I run it like so
phantomjs test-script.js http://phantomjs.org
I get an erorr of "SyntaxError: Parse Error". I'm newish to javascript and without a line number with the error I am lost. Here is the code
var args = require('system').args;
var url = "";
args.forEach(function(arg, i) {
url = arg;
});
var page = require('webpage').create();
var pageLoaded = function({
page.open(url, function (status) {
if (status !== 'success') {
console.log('Unable to access network');
} else {
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js", function() {
var data = page.evaluate(function() {
return $("body").html();
});
var title = page.evaluate(function () {
return document.title;
});
console.log('<title>' + title + '</title>');
console.log(data);
page.close();
phantom.exit();
});
}
});
});
var try_to = function() {
setTimeout(pageLoaded, 1000);
};
try_to();
I looked at PhantomJS sometimes gives "parse error" messages and getting more information from phantomjs "SyntaxError: Parse error" message Neither give me more information to debug. I've checked multiple sites and am not getting the gzip issue mentioned in that first link. I think it's something w/ the code. As if I remove the try_to() function, all things work.