In React Native i want to parse www.google.com
and get its element that has a class class="lnXdpd"
.
I'm unsure how to use querySelector
so once i fetch the url and have its string to parse it using querySelector
Fetch HTML page file content with Fetch API then parse with HTML Parser.
import { parse } from "node-html-parser";
async function parseURL() {
try {
// Smithsonian Museum Homepage
const response = await fetch("https://www.si.edu/");
const html = await response.text();
const parsed = parse(html, {
blockTextElements: {
script: false,
noscript: true,
style: true,
pre: true,
},
});
// Find elements with form-details class
console.log(parsed.querySelector(".form-details")?.toString());
} catch (error) {
console.log(error);
}
}
parseURL()
Demo - https://replit.com/@EmmanuelBYIRING/html-parser-url#index.js