Объект amazon id возвращает None, что бы я ни делал. В качестве эксперимента я попробовал этот точный код на объектах ebay id, и он сработал. Чем отличается Amazon? Я также уже пытался изменить html .parser на lxlm, но он по-прежнему возвращает:
AttributeError: объект 'NoneType' не имеет атрибута 'get_text'
Проблема может быть найдена в getPrice () def
from bs4 import BeautifulSoup
import time
import smtplib
URL = 'https://www.lego.com/en-us/product/darth-vader-s-castle-75251'
headers = {'Users-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36'}
wanted = 80
email = "help@gmail.com"
password = 'password'
Server_name = 'mail.gmail.com'
MAIL_USE_SSL=True
def sendMail():
subject = 'Ebay Price has Dropped!!'
mailtext = "Subject:"+subject+"\n\n"+URL
server = smtplib.SMTP(host='smtp.gmail.com', port=587)
server.ehlo()
server.starttls()
server.login(email,password)
server.sendmail(email,email,mailtext)
print("Sent Email")
pass
def trackPrice():
price = getPrice()
if price > wanted:
diff = (price - wanted)
diff = round(diff,5)
print(f"it's still ${diff} over-priced")
else:
print('cheaper')
sendMail()
def getPrice():
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.content,"html.parser")
price = soup.find(id="priceblock_ourprice").get_text().strip()[4:]
price = float(price)
print(price)
return price
if __name__ == "__main__":
while True:
trackPrice()
time.sleep(100)