function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
// getElementByXpath('//*[text()="标准分类"]')
var intervalID = setInterval(() => {
var element = getElementByXpath('//*[contains(text(),"结果")]')
var keyString=element.innerText.split(' ')[0].substring(2)
console.log('finalPrice----------------',element);
if((element)&&(keyString)){
console.log('keyString----------------',keyString);
window.open("https://www.baidu.com/s?ie=UTF-8&wd="+keyString,"width=800,height=600")
clearInterval(intervalID)
}
}, 900);
XPath定位与实时搜索:抓取关键信息并触发操作
本文介绍了一个JavaScript函数getElementByXpath,用于通过XPath表达式获取网页元素。通过定时器每900毫秒搜索包含特定文本'结果'的元素,并获取其首字符作为关键字,触发浏览器跳转到百度搜索。
3283

被折叠的 条评论
为什么被折叠?



