From 1daa223be71837fb6b36144c3f400e5f7c56eab8 Mon Sep 17 00:00:00 2001 From: Zynh0722 Date: Tue, 2 Apr 2024 19:27:00 -0700 Subject: [PATCH] getting all hrefs --- index.ts | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/index.ts b/index.ts index 42e28e0..2f60a5d 100644 --- a/index.ts +++ b/index.ts @@ -1,11 +1,9 @@ import { parse } from "node-html-parser"; -console.log("Hello via Bun!"); - const BASE_URL = "https://www.nasa.gov/gallery/human-spaceflight-mission-patches/"; -async function getPatchesHrefs() { +async function getPatchHrefs() { function getGalleryPageHref(page: number) { if (page > 1) { return `${BASE_URL}page/${page}/`; @@ -34,20 +32,10 @@ async function getPatchesHrefs() { patchHrefs.push.apply(patchHrefs, links); } + + return patchHrefs; } -const req = await fetch( - "https://www.nasa.gov/gallery/human-spaceflight-mission-patches/page/2/", -); -const data = parse(await req.text()); +const allPatches = await getPatchHrefs(); -const gallery = data - .getElementsByTagName("div") - .filter((el) => el.classList.contains("hds-gallery-items")) - .shift(); - -const links = gallery - ?.getElementsByTagName("a") - .map((el) => el.getAttribute("href")); - -console.log(links); +console.log(allPatches);