-2
Comparing the price of the same product every minute and notifying me when the value drops 50%. I used a While >= but it is returning an error indicating that you cannot use >= between str and int. It ends up returning the price as a string.
I’ll show you the code:
from selenium import webdriver
from time import sleep
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--hedless')
driver = webdriver.Chrome()
driver.get('https://www.magazineluiza.com.br/ssd-480gb-kingston-sata-rev-3-0-leituras-500mb-s-e-gravacoes-450mb-s-a400/p/220920100/in/ssdi/')
sleep(3)
produto = driver.find_element_by_xpath('/html/body/div[3]/div[5]/div[1]/div[2]/h1').text
preçoatual = driver.find_element_by_xpath('/html/body/div[3]/div[5]/div[1]/div[3]/div[2]/div[4]/div/div[2]/div/span[2]').text
preçoalvo = 300
while preçoatual >= preçoalvo:
print(preçoatual)
sleep(1)
print('preço alvo atingido')
____________________________________________________________________________
Código alterado após as sugestões do amigo:
from selenium import webdriver
from time import sleep
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--hedless')
driver = webdriver.Chrome()
driver.get('https://www.magazineluiza.com.br/ssd-480gb-kingston-sata-rev-3-0-leituras-500mb-s-e-gravacoes-450mb-s-a400/p/220920100/in/ssdi/')
sleep(3)
produto = driver.find_element_by_class_name('header-product__title').text
preçoatual = driver.find_element_by_class_name('price-template__text').text
preçoatual = preçoatual.replace(',', '.')
preçoatual = float(preçoatual)
preçoalvo = 300
print(produto)
while preçoatual > preçoalvo:
print(preçoatual)
driver.get('https://www.magazineluiza.com.br/ssd-480gb-kingston-sata-rev-3-0-leituras-500mb-s-e-gravacoes-450mb-s-a400/p/220920100/in/ssdi/')
sleep(3)
produto = driver.find_element_by_class_name('header-product__title').text
preçoatual = driver.find_element_by_class_name('price-template__text').text
preçoatual = preçoatual.replace(',', '.')
preçoatual = float(preçoatual)
sleep(5)
print('preço alvo atingido')
Bro, I followed your suggestions and it really worked! I tried the while block and it’s comparing right with the target price. When I change the target price by entering the current value, it exits the while loop and prints "target price reached". Let me take advantage and ask. What would be the best way for me to receive a notification? By email, Whatsapp, if possible. Also, is it too complicated to leave this code on a server? I’ll show you the already changed code by editing my question. You saved the day. Thanks.
– Viníciuscavalcante2000
You’re right about the while loop and the price I’m comparing. It’s looped in the same information.
– Viníciuscavalcante2000