Add contest ID in the data returned from the webscraper. Use selector to find option instead of using .find()

This commit is contained in:
Amelia 2022-06-06 15:03:17 +01:00
parent 93aa4f8aca
commit 1f8929e8e7
1 changed files with 7 additions and 2 deletions

View File

@ -36,6 +36,7 @@ type Contest = {
};
type EurmomilhoesData = {
id: string;
keys: Keys;
prizes: Prize[];
contests: Contest[];
@ -68,7 +69,7 @@ function getKey(element: cheerio.Cheerio<cheerio.Element>) {
* Scrape contests data from the selection menu
*/
function getContests($: cheerio.CheerioAPI) {
const selectionMenuOptions = $("select[name=selectContest]").find("option");
const selectionMenuOptions = $("select[name=selectContest] option");
const contests: Contest[] = [];
selectionMenuOptions.each(function (elem, i) {
@ -98,7 +99,6 @@ function getContestPage(contestId?: string) {
reject(result);
}
} else {
//???
const [resolved, result] = await handlePromise(
axios.get(EUROMILHOES_URL)
);
@ -119,6 +119,7 @@ function scrapeWebpage(content: string | Buffer): EurmomilhoesData {
//const result = fs.readFileSync("index.html");
let data: EurmomilhoesData = {
id: "",
keys: {
orderedKey: {
numbers: [],
@ -145,6 +146,9 @@ function scrapeWebpage(content: string | Buffer): EurmomilhoesData {
return data;
}
const selectedContest = $("select[name=selectContest] option");
const contestId = selectedContest.first().attr("value");
const orderedKey = getKey(keyLists.first());
const sortedKey = getKey(keyLists.eq(1));
@ -189,6 +193,7 @@ function scrapeWebpage(content: string | Buffer): EurmomilhoesData {
data.contests = getContests($);
data = {
id: contestId!,
keys: {
orderedKey: orderedKey,
sortedKey: sortedKey,