Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Amazon price tracker in Python

from bs4 import BeautifulSoup
import requests
import time
import smtplib
from email.message import EmailMessage

#### Email Info ####
# TODO: Update your email, password and recipient
my_email = "INSERT YOUR EMAIL"
# Don't let anyone see your password!
password = "INSERT YOUR PASSWORD"
recipient = "INSERT THE EMAIL YOU'RE SENDING IT TO"

# headers that the amazon webpage needs
headers = {
	"User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0",
	"Accept-Language" : "en-US,en;q=0.5"
}

# Getting the amazon website using the request library
response = requests.get("https://www.amazon.com.mx/Aud%C3%ADfonos-inal%C3%A1mbricos-QuietComfort-Amazon-integrada/dp/B0756CYWWD/ref=sr_1_5?__mk_es_MX=%C3%85M%C3%85%C5%BD%C3%95%C3%91&dchild=1&keywords=noise+cancelling+headphones&qid=1620086893&sr=8-5"
						, headers = headers)
amazon_web_page = response.text

soup = BeautifulSoup(amazon_web_page, 'lxml')
product = soup.title.string[0:68]

price = soup.select_one(selector="#priceblock_dealprice").string
price = price[1:6]
price = price.replace(",", "")
price = int(price)

def product_price_print():
	print(f"The product is: {product}. This product costs {price}. THEY ARE REAL CHEAP, BUY THEM!")

product_price_print()

the_product_is_cheaper = True
iterations = 0

while the_product_is_cheaper:
	time.sleep(0)
	minute = 0
	iteration = 0

	# If the target of the product is less than 4000, then It'll send the message
	if the_product_is_cheaper == True and product <= 4000:

		#Sending the message
		subject = f"{product} are on {price}!!!"
		body = f"

{product_price_print()}

 Your python bot (:"

		# build-up email details using email.message module
		message = EmailMessage()
		message["Subject"] = subject
		message["From"] = my_email
		message["To"] = recipient
		message.set_content(body)

		# send the message via smtp using details above
		with smtplib.SMTP("smtp.gmail.com", port=587) as connection:
			connection.starttls()
			connection.login(my_email, password=password)
			connection.send_message(message)

		the_product_is_cheaper = False
Comment

PREVIOUS NEXT
Code Example
Python :: html element python 
Python :: concatenate strings of numpy array python 
Python :: requirements.txt dev python 
Python :: plotly facet_grid python 
Python :: how to count number from 1 to 10 in python 
Python :: how to run test cases in python 
Python :: fixed size list in python 
Python :: Dictionary Cache 
Python :: np.random.randint to generate -1 +1 
Python :: error python 
Python :: pip not recognized 
Python :: how to define number in python 
Python :: django pk 
Python :: rotate array in python 
Python :: python How do you find the middle element of a singly linked list in one pass? 
Python :: pandas get tuples from dataframe 
Python :: id3 algorithm code in python 
Python :: numpy dataframe 
Python :: using hashlib module in python 
Python :: insertion sort 
Python :: boto3 python s3 
Python :: windows python absolute path 
Python :: django float validator 
Python :: numpy index of first true value 
Python :: python referenced before assignment in function 
Python :: explicitly free memory in Python code 
Python :: random number generator python 
Python :: qr decomposition python 
Python :: Python Pandas - How to write in a specific column in an Excel Sheet 
Python :: how to get django 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =