From dbef7ecb423ffc87917edd2e9501410d08691aa0 Mon Sep 17 00:00:00 2001 From: Phumrapee Limpianchop Date: Fri, 10 Mar 2023 15:04:19 +0900 Subject: [PATCH] chore: staged changes --- bun.lockb | Bin 8814 -> 8814 bytes package.json | 2 +- src/functions/getLotto.ts | 30 ++++++++++++++++-------------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/bun.lockb b/bun.lockb index 40c9b15d505f202c8ba6a6b57d3af87df11fca78..deb4c6a12b1c16a8fed18c94219b7eef0e79f0aa 100755 GIT binary patch delta 254 zcmaFo^3G*~o`Qz%`e5h#X4*{e_b$FDeTR*+b;gm`Tz!5m#_M9{x}3YS(eDT&vjr>T zxOniJA2ZfiE{a_wNBd{Iz@7MPiVfnoCk b;VDdPKn93yB^JcWXgoPkQGW9p=|gM)Q}1J$ delta 611 zcmaFo^3G*~p2FFmuX!HtIi`7`yMR9{D&(*8j1;j7e(RohvXAC#_s^-^=y!yX`8*rr z-6nYP@ep43c9aGG<^{r2nAm{vm0Db~*-9*kmC (selector: string) => + cheerio(selector) + .map((_, el) => cheerio(el).text()) + .toArray() export const getLotto = async (targetId: string | number) => { const url = `https://news.sanook.com/lotto/check/${targetId}` const $ = load(await fetch(url).then(o => o.text())) - - const scrapeText = (selector: string) => - $(selector) - .map((_, el) => $(el).text()) - .toArray() + const scraper = scrapeText($) const [ date, @@ -25,31 +27,31 @@ export const getLotto = async (targetId: string | number) => { $('#contentPrint > header > h2') .text() .substring($('#contentPrint > header > h2').text().indexOf(' ') + 1), - scrapeText( + scraper( '#contentPrint > div.lottocheck__resize > div.lottocheck__sec.lottocheck__sec--bdnone > div.lottocheck__table > div:nth-child(1) > strong.lotto__number' ), // prizeFirst - scrapeText( + scraper( '#contentPrint > div.lottocheck__resize > div.lottocheck__sec.lottocheck__sec--bdnone > div.lottocheck__sec--nearby > strong.lotto__number' ), // prizeFirstNear - scrapeText( + scraper( '#contentPrint > div.lottocheck__resize > div:nth-child(2) > div > span.lotto__number' ), // prizeSecond - scrapeText( + scraper( '#contentPrint > div.lottocheck__resize > div:nth-child(3) > div > span' ), // prizeThird - scrapeText( + scraper( '#contentPrint > div.lottocheck__resize > div.lottocheck__sec.lottocheck__sec--font-mini.lottocheck__sec--bdnoneads > div.lottocheck__box-item > span.lotto__number' ), // prizeForth - scrapeText( + scraper( '#contentPrint > div.lottocheck__resize > div:nth-child(7) > div > span.lotto__number' ), // prizeFifth - scrapeText( + scraper( '#contentPrint > div.lottocheck__resize > div.lottocheck__sec.lottocheck__sec--bdnone > div.lottocheck__table > div:nth-child(2) > strong.lotto__number' ), // runningNumberFrontThree - scrapeText( + scraper( '#contentPrint > div.lottocheck__resize > div.lottocheck__sec.lottocheck__sec--bdnone > div.lottocheck__table > div:nth-child(3) > strong.lotto__number' ), // runningNumberBackThree - scrapeText( + scraper( '#contentPrint > div.lottocheck__resize > div.lottocheck__sec.lottocheck__sec--bdnone > div.lottocheck__table > div:nth-child(4) > strong.lotto__number' ), // runningNumberBackTwo ])