“JavaScript xpath” Ответ

Как получить доступ к XPath в JS

function getElementByXpath(path) {
  return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
Worried Walrus

JavaScript xpath

const fs = require("fs");const xpath = require("xpath-html"); // Assuming you have an html file locally,// Here is the content that I scraped from www.shopback.sgconst html = fs.readFileSync(`${__dirname}/shopback.html`, "utf8"); // Don't worry about the input much,// you are able to use the HTML response of an HTTP request,// as long as the argument is a string type, everything should be fine.const node = xpath.fromPageSource(html).findElement("//*[contains(text(), 'with love')]"); console.log(`The matched tag name is "${node.getTagName()}"`);console.log(`Your full text is "${node.getText()}"`);
Frantic Finch

Ответы похожие на “JavaScript xpath”

Вопросы похожие на “JavaScript xpath”

Больше похожих ответов на “JavaScript xpath” по JavaScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования