Get first two pages of event links

This commit is contained in:
Clarence Chan committed 2024-05-29 15:02:55 -04:00
1 parent b7ff5d369d
commit ef8fe2b74f
1 file changed
+16 -2
+16 -2
View File
@@ -8,8 +8,13 @@ import { decode } from "html-entities";
* of URL strings of UFC events * of URL strings of UFC events
*/ */
async function getEventLinks() { async function getEventLinks() {
let url = "https://www.ufc.com/events"; // Get first two pages of event links
try { let urls = [
"https://www.ufc.com/events?page=0",
"https://www.ufc.com/events?page=1",
];
async function getEventLinksFromUrl(url) {
const response = await fetch(url); const response = await fetch(url);
const text = await response.text(); const text = await response.text();
const root = parse(text); const root = parse(text);
@@ -20,6 +25,15 @@ async function getEventLinks() {
(html) => `https://www.ufc.com${html.firstChild.getAttribute("href")}` (html) => `https://www.ufc.com${html.firstChild.getAttribute("href")}`
); );
return links;
}
try {
urls = urls.map(getEventLinksFromUrl);
let links = await Promise.all(urls);
links = links.flat();
console.log("\nEvent links found:"); console.log("\nEvent links found:");
console.log(links); console.log(links);
return links; return links;