44import smtplib
55from email .mime .text import MIMEText
66
7+
78def get_amazon_product_price (product_url ):
89 headers = {
910 "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
@@ -13,7 +14,7 @@ def get_amazon_product_price(product_url):
1314 if response .status_code == 200 :
1415 soup = BeautifulSoup (response .content , 'html.parser' )
1516 price_element = soup .find ('span' , id = 'priceblock_ourprice' )
16-
17+
1718 if price_element :
1819 price_text = price_element .get_text ()
1920 return price_text .strip ()
@@ -23,6 +24,7 @@ def get_amazon_product_price(product_url):
2324 else :
2425 return "Failed to retrieve data from Amazon"
2526
27+
2628def send_email (subject , message ):
2729 sender_email = '[email protected] ' 2830 sender_password = 'your_sender_password'
@@ -39,10 +41,11 @@ def send_email(subject, message):
3941 server .sendmail (sender_email , recipient_email , msg .as_string ())
4042 server .quit ()
4143
44+
4245if __name__ == "__main__" :
4346 amazon_product_url = "https://www.amazon.com/dp/B07RF1XD36/"
4447 target_price = 500 # Set your desired target price
45-
48+
4649 while True :
4750 current_price = get_amazon_product_price (amazon_product_url )
4851 print (f"Current Price: { current_price } " )
0 commit comments