how to ignore errors in phantomjs

后端 未结 1 1504
Happy的楠姐
Happy的楠姐 2020-12-29 04:49

I have a web crawler and I use phantomjs to parse pages, I want to get the html, but I always get this type of errors in the output before the html code

Ref         


        
相关标签:
1条回答
  • 2020-12-29 05:19

    The easiest way is to add an error handler to phantom.onerror or webpage.onerror. These callbacks are invoked when there is a JavaScript execution error (in the page or in your script).

    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 + '")' : ''));
            });
        }
        // uncomment to log into the console 
        // console.error(msgStack.join('\n'));
    };
    
    0 讨论(0)
提交回复
热议问题