mirror of
https://github.com/clarencechaan/ufc-cal.git
synced 2026-10-19 18:10:58 -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
|
* 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;
|
||||||
|
|||||||
Reference in new issue
Block a user