2017-07-17 45 views
0

我在Windows 7中使用phantom js 2.1.1。我試圖打印所有innerhtml的列表項。Phantomjs 2.1.1 querySelectorAll()無法打印所有節點列表的innerHTML

我的代碼

var nl =pageCv.evaluate(function(){ 
       return document.querySelectorAll("#main_tabs > ul >li"); 
      }); 
      console.log('main tab Lenght :' + nl.length); 
      for (var i=0; i<nl.length; i++) { 
      console.log('id of ' + nl[i].innerHTML);  
      } 

流汗此錯誤

main tab Lenght :3 
TypeError: null is not an object (evaluating 'nl[i].innerHTML') 

如何打印節點列表中的所有的innerHTML? 請幫幫我

+0

問題是什麼? – Vaviloff

回答

-1
var nl = pageCv.evaluate(function(s) { 

var simpleArray = [], 
    forEach = Array.prototype.forEach, 
    nodes = document.querySelectorAll("#main_tabs > ul >li"); 

    forEach.call(nodes, function(el){ 
     simpleArray.push(el.innerHTML); 
    }); 
    return simpleArray; 
}, 'something'); 

console.log('main tab Lenght :' + nl.length); 

for(var i=0; i < nl.length; i++) 
{ 
    console.log(nl[i]); 
};