getting all hrefs
parent
08d753432f
commit
1daa223be7
22
index.ts
22
index.ts
|
@ -1,11 +1,9 @@
|
||||||
import { parse } from "node-html-parser";
|
import { parse } from "node-html-parser";
|
||||||
|
|
||||||
console.log("Hello via Bun!");
|
|
||||||
|
|
||||||
const BASE_URL =
|
const BASE_URL =
|
||||||
"https://www.nasa.gov/gallery/human-spaceflight-mission-patches/";
|
"https://www.nasa.gov/gallery/human-spaceflight-mission-patches/";
|
||||||
|
|
||||||
async function getPatchesHrefs() {
|
async function getPatchHrefs() {
|
||||||
function getGalleryPageHref(page: number) {
|
function getGalleryPageHref(page: number) {
|
||||||
if (page > 1) {
|
if (page > 1) {
|
||||||
return `${BASE_URL}page/${page}/`;
|
return `${BASE_URL}page/${page}/`;
|
||||||
|
@ -34,20 +32,10 @@ async function getPatchesHrefs() {
|
||||||
|
|
||||||
patchHrefs.push.apply(patchHrefs, links);
|
patchHrefs.push.apply(patchHrefs, links);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return patchHrefs;
|
||||||
}
|
}
|
||||||
|
|
||||||
const req = await fetch(
|
const allPatches = await getPatchHrefs();
|
||||||
"https://www.nasa.gov/gallery/human-spaceflight-mission-patches/page/2/",
|
|
||||||
);
|
|
||||||
const data = parse(await req.text());
|
|
||||||
|
|
||||||
const gallery = data
|
console.log(allPatches);
|
||||||
.getElementsByTagName("div")
|
|
||||||
.filter((el) => el.classList.contains("hds-gallery-items"))
|
|
||||||
.shift();
|
|
||||||
|
|
||||||
const links = gallery
|
|
||||||
?.getElementsByTagName("a")
|
|
||||||
.map((el) => el.getAttribute("href"));
|
|
||||||
|
|
||||||
console.log(links);
|
|
||||||
|
|
Loading…
Reference in New Issue