From 1f8929e8e7f0a6ed47e464c59d0b074c3039155f Mon Sep 17 00:00:00 2001 From: Amelia <9247739-limesey@users.noreply.gitlab.com> Date: Mon, 6 Jun 2022 15:03:17 +0100 Subject: [PATCH] Add contest ID in the data returned from the webscraper. Use selector to find option instead of using .find() --- src/scrapers/euromilhoes.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/scrapers/euromilhoes.ts b/src/scrapers/euromilhoes.ts index 9439e63..8f0fb29 100644 --- a/src/scrapers/euromilhoes.ts +++ b/src/scrapers/euromilhoes.ts @@ -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) { * 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,