Ir ao conteúdo
  • Cadastre-se

Assis Dantas

Membro Júnior
  • Posts

    1
  • Cadastrado em

  • Última visita

posts postados por Assis Dantas

  1. Boa noite coelgas,

     

    Estou estudando ciência de dados e resolvi praticar alguns códigos para ver o seu funcionamento. Estava tentando fazer um scraping usando Python e Selenium e o WebDriver do Chrome. Toda vez que rodo um script ele me retorna o erro:

    selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[contains(@class, '2S1VP')]"}
    

    Segue a linha de código para buscar a classe:

     

    self.caixa_de_pesquisa = self.driver.find_element_by_xpath("//div[contains(@class, '2S1VP')]")

    Já tentei buscar a classe sem XPath (//span), e obtive o mesmo erro. Não é a primeira vez que tento rodar um scraping e não tenho êxito. Abaixo, um trecho do código:

     

    import os
    import time
    import re
    import requests
    import json
    from chatterbot.trainers import ListTrainer
    from chatterbot import ChatBot
    from selenium import webdriver
    
    
    
    class wppbot:
    
        dir_path = os.getcwd()
    
        def __init__(self, nome_bot):
            print(self.dir_path)
            self.bot = ChatBot(nome_bot)
            #self.bot.set_trainer(ListTrainer)
            self.trainer = ListTrainer(self.bot)
            #self.trainer.train(self.conversas)
    
            self.chrome = self.dir_path+'/chromedriver'
    
            self.options = webdriver.ChromeOptions()
            self.options.add_argument(r"user-data-dir="+self.dir_path+"/profile/wpp")
            self.options.add_argument('--headless')
            self.options.add_argument('--no-sandbox')
            self.options.add_argument('--disable-dev-shm-usage')
            self.driver = webdriver.Chrome(self.chrome, chrome_options=self.options)
    
        def inicia(self,nome_contato):
    
            self.driver.get('https://web.whatsapp.com/')
            self.driver.implicitly_wait(20)
    
            self.caixa_de_pesquisa = self.driver.find_element_by_xpath("//div[contains(@class, '2S1VP')]")
    
    
            self.caixa_de_pesquisa.send_keys(nome_contato)
            time.sleep(2)
            print(nome_contato)
            self.contato = self.driver.find_element_by_xpath('//span[@title = "{}"]'.format(nome_contato))
            self.contato.click()
            time.sleep(2)

    Alguém pode ajudar?

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Ebook grátis: Aprenda a ler resistores e capacitores!

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!