2013-10-18 9 views
23

मैं एक वेब क्रॉलर है में त्रुटियों को अनदेखा करने के लिए और मैं phantomjs उपयोग करते हैं, पृष्ठों पार्स करने के लिए मैं एचटीएमएल प्राप्त करना चाहते हैं, लेकिन मैं हमेशा एचटीएमएल कोडकैसे phantomjs

ReferenceError: Can't find variable: collapse_content_selector 

    http://staticloads.com/js/toggle.js?v=2013.10.04:135 
TypeError: 'undefined' is not a function (evaluating '$('[placeholder]').placeholderLabel()') 
से पहले उत्पादन में त्रुटियों के इस प्रकार प्राप्त

मैं इसे

उत्तर

37

phantom.onerror या webpage.onerror पर एक त्रुटि हैंडलर जोड़ने का सबसे आसान तरीका कैसे रोक सकता हूं। ये कॉलबैक लागू कर रहे हैं जब वहाँ एक JavaScript निष्पादन त्रुटि (पेज में या अपने लिपि में) है।

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')); 
};