diff --git a/common/amazon.ts b/common/amazon.ts index 1632bc0..e535d02 100644 --- a/common/amazon.ts +++ b/common/amazon.ts @@ -185,10 +185,11 @@ async function parseItem($: CheerioAPI, url: string): Promise { } // Get other offer prices - const aodOffers = $('#aod-offer').toArray() + const aodOffers = $('#aod-offer-price').toArray() aodOffers.forEach(o => { - const price = $(o).find('.a-offscreen').text().trim() + const price = $(o).find('.a-offscreen').first().text().trim() + console.log('AOD Price: ' + price) if (parseFloat(priceFormat(price))) priceElms.push(price) }) diff --git a/common/browser.ts b/common/browser.ts index 3e4872d..69e9850 100644 --- a/common/browser.ts +++ b/common/browser.ts @@ -23,6 +23,12 @@ export async function initBrowser() { } export async function getPage(url: string) { + // IF it's a product link, append aod=1 to the URL + if (url.includes('/dp/')) { + if (url.includes('?')) url += '&aod=1' + else url += '?aod=1' + } + debug.log(`URL: ${url}`, 'info') const page = await global?.browser.newPage() @@ -57,8 +63,6 @@ export async function getPage(url: string) { debug.log('Waiting a couple seconds for JavaScript to load...', 'info') - if (await page.$('.olp-text-box') !== null) await page.click('.olp-text-box') - await new Promise(r => setTimeout(r, 1500)) const html = await page.evaluate(() => document.body.innerHTML).catch(e => debug.log(e, 'error'))