54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
|
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() {
|
||
|
function getGalleryPageHref(page: number) {
|
||
|
if (page > 1) {
|
||
|
return `${BASE_URL}page/${page}/`;
|
||
|
} else {
|
||
|
return BASE_URL;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
let patchHrefs: string[] = [];
|
||
|
|
||
|
for (let i = 0; i <= 7; i++) {
|
||
|
const req = await fetch(
|
||
|
"https://www.nasa.gov/gallery/human-spaceflight-mission-patches/page/2/",
|
||
|
);
|
||
|
const data = parse(await req.text());
|
||
|
|
||
|
const gallery = data
|
||
|
.getElementsByTagName("div")
|
||
|
.filter((el) => el.classList.contains("hds-gallery-items"))
|
||
|
.shift();
|
||
|
|
||
|
const links = gallery
|
||
|
?.getElementsByTagName("a")
|
||
|
.map((el) => el.getAttribute("href"))
|
||
|
.filter((el) => el) as string[];
|
||
|
|
||
|
patchHrefs.push.apply(patchHrefs, links);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const req = await fetch(
|
||
|
"https://www.nasa.gov/gallery/human-spaceflight-mission-patches/page/2/",
|
||
|
);
|
||
|
const data = parse(await req.text());
|
||
|
|
||
|
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);
|