Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

fix to work with new amazon design #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions 2. search/amazon.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ const puppeteer = require('puppeteer')
const screenshot = 'amazon_nyan_cat_pullover.png'
try {
(async () => {
const browser = await puppeteer.launch()
const browser = await puppeteer.launch({ headless: false})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to have { headless: true } here

const page = await browser.newPage()
await page.setViewport({ width: 1280, height: 800 })
await page.goto('https://www.amazon.com')
await page.type('#twotabsearchtextbox', 'nyan cat pullover')
await page.click('input.nav-input')
await page.waitForSelector('#resultsCol')
await page.waitFor(3000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an anti-pattern. waitFor(3000) or any wait period that does not wait for an explicit element is bound to break. Please wait for a specific element.

await page.waitForSelector('#s-skipLinkTargetForMainSearchResults')
await page.screenshot({path: 'amazon_nyan_cat_pullovers_list.png'})
await page.click('#pagnNextString')
await page.waitForSelector('#resultsCol')
await page.click('li[class="a-last"] > a')
await page.waitFor(3000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment on waitFor() above.

await page.waitForSelector('#s-skipLinkTargetForMainSearchResults')
const pullovers = await page.$$('a.a-link-normal.a-text-normal')
await pullovers[2].click()
await page.waitForSelector('#ppd')
Expand Down