PhantomJS Parse error on specific sites

When I try to run the following extremely simple PhantomJS script, I get a parsing error:

var page = require('webpage').create(); page.open('http://compare.nissanusa.com/nissan_compare/NNAComparator/TrimSelect.jsp', function (status) {}); 

Does anyone know why this might happen? The error message is not at all useful ... It just says “Analysis error”.

Could this be a bug in PhantomJS?

I am using PhantomJS version 1.9. I can run the above script with other URLs, but for some reason certain URLs return a parsing error ...

Any help would be greatly appreciated!

+4
source share
1 answer

This is simply because there is a javascript error on the website http://compare.nissanusa.com/nissan_compare/NNAComparator/TrimSelect.jsp . Parse Error not due to your code.

Phantomjs doesn’t really like the js error when loading the page, so it’s important to add an error handler.

To easily spot an error on a web page, be it a syntax error or another exception, use page.onError .

Here is an example:

 page.onError = function(msg, trace) { var msgStack = ['ERROR: ' + msg]; if (trace && trace.length) { msgStack.push('TRACE:'); trace.forEach(function(t) { msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function + '")' : '')); }); } console.error(msgStack.join('\n')); }; 
+3
source

Source: https://habr.com/ru/post/1493396/


All Articles