Skip to content

Instantly share code, notes, and snippets.

@creativesalam
Forked from fnneves/amazon_bot_2.py
Created October 30, 2020 11:10
Show Gist options
  • Save creativesalam/a3d18a6fe353673c81452e9ee0d23df7 to your computer and use it in GitHub Desktop.
Save creativesalam/a3d18a6fe353673c81452e9ee0d23df7 to your computer and use it in GitHub Desktop.
# product title
title = soup.find(id='productTitle').get_text().strip()
# to prevent script from crashing when there isn't a price for the product
try:
price = float(soup.find(id='priceblock_ourprice').get_text().replace('.', '').replace('€', '').replace(',', '.').strip())
except:
price = ''
# review score
review_score = float(soup.select('.a-star-4-5')[0].get_text().split(' ')[0].replace(",", "."))
# how many reviews
review_count = int(soup.select('#acrCustomerReviewText')[0].get_text().split(' ')[0].replace(".", ""))
# checking if there is "Out of stock" and if not, it means the product is available
try:
soup.select('#availability .a-color-state')[0].get_text().strip()
stock = 'Out of Stock'
except:
stock = 'Available'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment