Skip to content

Commit

Permalink
fix: aod offers
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Nov 19, 2023
1 parent 40b37e6 commit 929e0dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions common/amazon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,11 @@ async function parseItem($: CheerioAPI, url: string): Promise<ProductInfo> {
}

// 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)
})

Expand Down
8 changes: 6 additions & 2 deletions common/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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'))
Expand Down

0 comments on commit 929e0dd

Please sign in to comment.