result=""
for (var i = 2; i <= 100; i++) {
var xpath = '//*[@id="app"]/div/div[3]/div[1]/div[3]/div/div[2]/div/div[1]/div[1]/div/div/div/div/div/div/div[2]/table/tbody/tr[' + i + ']/td[4]/div[1]/span[1]/span/a';
var xpathResult = document.evaluate(
xpath,
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
);
// 检查是否找到匹配的元素
if (xpathResult.singleNodeValue) {
var aContent = xpathResult.singleNodeValue.textContent;
result+="http://"+aContent+":54321"+"\n"
console.log("找到匹配的a标签内容:", aContent);
}else break;
}
console.log(result)
标签:网页,js,爬取,result,var,table
From: https://www.cnblogs.com/guowenrui/p/17967567