adrianhajdin / pricewise

Dive into web scraping and build a Next.js 13 eCommerce price tracker within a single video that teaches you data scraping, cron jobs, sending emails, deployment, and more.
https://pricewise-jsm.vercel.app
480 stars 145 forks source link

`outOfStock` variable always returning false even when the product is out of stock #11

Open hatiprithwish opened 9 months ago

hatiprithwish commented 9 months ago

The existing outOfStock variable will always return false even if the product is out of stock. Reason being, when any product page has "Currently unavailable." text, it is within two nested spans within the #availablity div.

Screenshot 2023-12-29 174622

To fix the problem, I'm using this code block and changed the named of the variable from outOfStock to isOutOfStock as it returns a Boolean.

const isOutOfStock =
      $(
        ".a-declarative span.a-size-medium.a-color-success" ||
          "#availablity span"
      )
        .text()
        .trim()
        .toLowerCase() === "currently unavailable.";