import scrape from "scrape-it"; import { parse } from "node-html-parser"; const usingScrapeIt = async () => { const { data } = await scrape("https://www.webtekno.com", { posts: { listItem: ".content-timeline__item", data: { title: ".content-timeline__detail__title", author: ".content-timeline__detail__author", image: { selector: ".content-timeline__media img", attr: "data-original", }, href: { selector: "a", attr: "href", }, }, }, }); console.log(data); }; const usingFetch = async () => { const response = await fetch("https://www.webtekno.com").then((res) => res.text(), ); const root = parse(response); const posts = root.querySelectorAll(".content-timeline__item"); const postsArray = [] as any; for (const post of posts) { const title = post.querySelector(".content-timeline__detail__title"); const author = post.querySelector(".content-timeline__detail__author"); const image = post.querySelector(".content-timeline__media img"); const href = post.querySelector("a"); postsArray.push({ title: title?.text, author: author?.text, image: image?.getAttribute("data-original"), href: href?.getAttribute("href"), }); } console.log(postsArray); };