mirror of
https://github.com/clarencechaan/ufc-cal.git
synced 2026-10-19 00:38:30 -07:00
Get first two pages of event links
This commit is contained in:
1 parent
b7ff5d369d
commit
ef8fe2b74f
1 file changed
+16
-2
@@ -8,8 +8,13 @@ import { decode } from "html-entities";
|
||||
* of URL strings of UFC events
|
||||
*/
|
||||
async function getEventLinks() {
|
||||
let url = "https://www.ufc.com/events";
|
||||
try {
|
||||
// Get first two pages of event links
|
||||
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 text = await response.text();
|
||||
const root = parse(text);
|
||||
@@ -20,6 +25,15 @@ async function getEventLinks() {
|
||||
(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(links);
|
||||
return links;
|
||||
|
||||
Reference in new issue
Block a user