phantomjs 中如何使用xpath

function getNodeInfo(inputcsvPath)
{
var htmlnodeInfo = page.evaluate(function () {
//_Ltg
var XPATH = "//div[@id='_Ltg']";

// var rootnode = document.getElementById(XPATH_ROOT);
// return rootnode;
var allElements=document.evaluate(XPATH , document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);;
for(var i = 0; i < allElements.snapshotLength; i++)
{ 
thisElement = allElements.snapshotItem(i);//循环获取节点 
return thisElement.innerText;
}

});
fs.write(inputcsvPath, htmlnodeInfo + "\r\n", 'a');
}

  

posted @ 2016-04-15 11:52  公众号python学习开发  阅读(502)  评论(0编辑  收藏  举报