mirror of
https://github.com/clarencechaan/ufc-cal.git
synced 2026-10-19 08:38:30 -07:00
Implement getAllDetailedEvents function in scrape.js
This commit is contained in:
1 parent
bb1140f8fb
commit
e159511920
1 file changed
+29
-2
@@ -24,10 +24,15 @@ async function getDetailsFromEventLink(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);
|
||||||
let name = root.querySelector("title").innerText.split(" | ")[0];
|
let name = root.querySelector("title").innerText.replace(" | UFC", "");
|
||||||
let date = root
|
let date = root
|
||||||
.querySelector(".c-hero__headline-suffix")
|
.querySelector(".c-hero__headline-suffix")
|
||||||
.getAttribute("data-timestamp");
|
.getAttribute("data-timestamp");
|
||||||
|
let prelimsTime = root
|
||||||
|
.querySelector(
|
||||||
|
"#main-card-id > ul > li:nth-child(2) > div > div > div.c-listing-viewing-option__column.c-listing-viewing-option__column--left > div.c-listing-viewing-option__time.tz-time-change-inner"
|
||||||
|
)
|
||||||
|
?.getAttribute("data-timestamp");
|
||||||
let location = root
|
let location = root
|
||||||
.querySelector(".field--name-venue")
|
.querySelector(".field--name-venue")
|
||||||
.innerText.replaceAll("\n", "")
|
.innerText.replaceAll("\n", "")
|
||||||
@@ -78,9 +83,31 @@ async function getDetailsFromEventLink(url) {
|
|||||||
fightCard = fightCard.map(convertLiToStr);
|
fightCard = fightCard.map(convertLiToStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
let details = { name, date, location, fightCard, mainCard, prelims };
|
[name, location] = [decode(name), decode(location)];
|
||||||
|
let details = {
|
||||||
|
name,
|
||||||
|
url,
|
||||||
|
date,
|
||||||
|
prelimsTime,
|
||||||
|
location,
|
||||||
|
fightCard,
|
||||||
|
mainCard,
|
||||||
|
prelims,
|
||||||
|
};
|
||||||
return details;
|
return details;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getAllDetailedEvents() {
|
||||||
|
let events = [];
|
||||||
|
try {
|
||||||
|
events = await getEventLinks();
|
||||||
|
events = events.map(getDetailsFromEventLink);
|
||||||
|
events = await Promise.all(events);
|
||||||
|
return events;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user