Thank you! I'm still running into trouble, so I thought I'd post my complete script. Essentially what I'm trying to do is run a script where it checks the price of a suit and lets me know when it's dropped below $400.
import requests
from bs4 import BeautifulSoup
import time
import smtplib
URL = "https://shop.nordstrom.com/s/peter-millar-classic-fit-solid-wool-suit/4294847/full?origin=category-personalizedsort&breadcrumb=Home%2FMen%2FClothing%2FSuits%20%26%20Separates&fashioncolor=Black&fashionsize=15%3A46r~~42&color=charcoal"
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0"}
Wanted_Price = 400
def trackprice():
price = int(float(getprice()))
if price > Wanted_Price:
diff = price - Wanted_Price
print(f"It's still ${diff} too expensive")
# else:
# print("Cheaper!")
if(price < Wanted_Price):
send_mail()
def getprice():
# page = requests.get(URL, headers=headers)
html_string='''<h1 itemprop="name" overrideelementwith="div" class=" _6YOLH _1JtW7 _2VF_A_2OMMP">Classic Fit Solid Wool Suit</h1>
<span id="current-price-string" class="_1ds4c">$338.00</span>'''
soup = BeautifulSoup(html_string, 'html.parser')
row = soup.find('span')
row
print(row.get_text())
row = soup.find('h1')
print(row.get_text())
def send_mail():
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login('
[email protected]', 'password')
subject = 'Nordstrom price went wown'
body = 'Check link:
https://shop.nordstrom.com/s/peter-milla...r=charcoal'
msg = f"Subject: {subject}\n\n{body}\n\n"
server.sendmail(
'
[email protected]',
'
[email protected]',
msg
)
print('Email has been sent')
server.quit()
if __name__ == "__main__":
while True:
trackprice()
time.sleep(60*60)