4
4
import smtplib
5
5
from email .mime .text import MIMEText
6
6
7
+
7
8
def get_amazon_product_price (product_url ):
8
9
headers = {
9
10
"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):
13
14
if response .status_code == 200 :
14
15
soup = BeautifulSoup (response .content , 'html.parser' )
15
16
price_element = soup .find ('span' , id = 'priceblock_ourprice' )
16
-
17
+
17
18
if price_element :
18
19
price_text = price_element .get_text ()
19
20
return price_text .strip ()
@@ -23,6 +24,7 @@ def get_amazon_product_price(product_url):
23
24
else :
24
25
return "Failed to retrieve data from Amazon"
25
26
27
+
26
28
def send_email (subject , message ):
27
29
sender_email = 'your_sender_email@gmail.com'
28
30
sender_password = 'your_sender_password'
@@ -39,10 +41,11 @@ def send_email(subject, message):
39
41
server .sendmail (sender_email , recipient_email , msg .as_string ())
40
42
server .quit ()
41
43
44
+
42
45
if __name__ == "__main__" :
43
46
amazon_product_url = "https://www.amazon.com/dp/B07RF1XD36/"
44
47
target_price = 500 # Set your desired target price
45
-
48
+
46
49
while True :
47
50
current_price = get_amazon_product_price (amazon_product_url )
48
51
print (f"Current Price: { current_price } " )
0 commit comments