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