Skip to content

Instantly share code, notes, and snippets.

@BMU-Verlag
Last active April 21, 2020 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BMU-Verlag/d88b2bc75fb016be933b51ceea0398c0 to your computer and use it in GitHub Desktop.
Save BMU-Verlag/d88b2bc75fb016be933b51ceea0398c0 to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
URL = 'your_url'
TARGET_PRICE = your_price (e.g. 10.0)
HEADERS = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/80.0.3987.163 Safari/537.36'
}
def parse_price(price_text):
price_text = price_text.replace('€', '')
price_text = price_text.replace('EUR', '')
price_text = price_text.strip()
price_text = price_text.replace('.', '')
price_text = price_text.replace(',', '.')
return float(price_text)
page = requests.get(URL, headers=HEADERS)
soup = BeautifulSoup(page.content, 'html5lib')
title_span = soup.find('span', id='productTitle')
name = ''
if title_span is not None:
name = title_span.get_text().strip()
price = 0.0
price_span = soup.find('span', id='priceblock_dealprice')
if price_span is None:
price_span = soup.find('span', id='priceblock_ourprice')
if price_span is None:
price_span = soup.find('span', class_=a-color-price')
if price_span is not None:
price = parse_price(price_span.get_text())
if price <= TARGET_PRICE:
print (URL, name, price)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment