“JavaScript xpath” Código de respuesta

Cómo acceder a XPath en 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

Respuestas similares a “JavaScript xpath”

Preguntas similares a “JavaScript xpath”

Más respuestas relacionadas con “JavaScript xpath” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código