0
  • I want to use the span tag to access the class, and not through xpatch, well, when I try to get an empty array or an error, in this site I parsed the prices and when they change, they come to the telegram bot only prices and names there is an infinite loop after the start button, it will endlessly check the list in which there is already data it will check and if the price changes it will send a response in telegram

https://i.sstatic.net/oXloI.png

# -*- coding: utf8 -*-
    
        import telebot 
        import re
        from selenium import webdriver
        from time import sleep
        PATH ="Desktop\parser\chromedriver"
        driver = webdriver.Chrome(PATH)
        bot = telebot.TeleBot("bot api")
        
        @bot.message_handler(commands=['start'])
        
        
        def start(message):  
            bot.send_message(message.chat.id, "Create a price list")
        
            # eldorado
           
            link_eldo = "https://www.eldorado.ru/c/smartfony/b/APPLE/?page=1" 
            driver.get(link_eldo)
            
            def func (i):
                i = i + 1
                return i
            
            name_eldo_product = driver.find_elements_by_xpath("/html/body/div[3]/div[1]/div[2]/div[8]/div[2]/div[1]/ul/li['func(0)']/div[2]/div[1]/div[2]/a")
            price_eldo_product = driver.find_elements_by_xpath("/html/body/div[3]/div[1]/div[2]/div[8]/div[2]/div[1]/ul/li['func(0)']/div[2]/div[2]/div[2]/span")
        
         
0

1 Answer 1

0

Forget these kind of paths: "/html/body/div[3]/div[1]/div[2]/div[8]/div[2]/div[1]/ul/li['func(0)']/div[2]/div[2]/div[2]/span", navigate by element attributes.

I'd do something like this:

my_data = {}
for item in driver.find_elements_by_xpath('//*[@data-dy="product"]'):
   name_elem = item.find_element_by_xpath('.//*[@data-dy="title"]') 
   price = item.find_element_by_xpath('.//span[@data-pc="offer_price"]')
   my_data[name_elem.text] =  price.text

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.