AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / computer / Perguntas / 1801841
Accepted
Peter Long
Peter Long
Asked: 2023-08-02 05:36:20 +0800 CST2023-08-02 05:36:20 +0800 CST 2023-08-02 05:36:20 +0800 CST

NoSuchElementException ao coletar dados do URL do Discogs usando o Selenium

  • 772

Eu tento extrair alguns dados de um URL do Discogs usando o Selenium, mas tenho medo de selecionar incorretamente a tag correta do Selenium

Eu começo a partir DESTE url

E eu tento entrar no console esta saída

Artista 1: The Sound Man Featuring Mercy (3) – The Factory
Testo elemento 1: The Factory (Original Mix)    
Testo elemento 2: The Factory (Bass Dub)    
Testo elemento 3: The Factory (Junior's Factory Dub)    
Testo elemento 4: The Factory (Sexapella)   
Testo elemento 5: The Factory (Klubb Kidz Flava Dub)    
Testo elemento 6: The Factory (Klubb Kidz School Dub)   
Testo elemento 7: The Factory (Duke's Massive Blast)

Para descartar isso, dou uma olhada com DevTools of Selenium nessa seção e vejo isso

https://i.imgur.com/Q8Sbdk2.png

Mas eu recebo esses erros

C:\Users\Peter\Desktop\script\BLOCCO 1\selenium>python canzonidiscogs.py
Inserisci l'URL di Discogs: https://www.discogs.com/it/master/103917-The-Sound-Man-Featuring-Mercy-The-Factory

DevTools listening on ws://127.0.0.1:59139/devtools/browser/b0724a48-9b6e-401f-8e58-7882ae487739
Artista 1: The Sound Man Featuring Mercy (3) – The Factory
Traceback (most recent call last):
  File "C:\Users\Peter\Desktop\script\BLOCCO 1\selenium\canzonidiscogs.py", line 21, in <module>
    artist = element.find_element(By.CSS_SELECTOR, 'td[class^="title_"]> a').text
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 417, in find_element
    return self._execute(Command.FIND_CHILD_ELEMENT, {"using": by, "value": value})["value"]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 395, in _execute
    return self._parent.execute(command, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 346, in execute
    self.error_handler.check_response(response)
  File "C:\Python311\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"td[class^="title_"]> a"}
  (Session info: chrome=115.0.5790.110); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
Stacktrace:
Backtrace:
        GetHandleVerifier [0x0069A813+48355]
        (No symbol) [0x0062C4B1]
        (No symbol) [0x00535358]
        (No symbol) [0x005609A5]
        (No symbol) [0x00560B3B]
        (No symbol) [0x00559AE1]

Eu uso esse código para realizar a extração

from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# Chiedi all'utente di inserire l'URL di Discogs
url = input("Inserisci l'URL di Discogs: ")

driver = Chrome()
wait = WebDriverWait(driver, 10)

driver.get(url)

title = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'h1[class^="title_"]'))).text
print(f"Artista 1: {title}")

# Utilizziamo il selettore CSS fornito per selezionare gli elementi della tabella
container = wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, 'div[class^="content_1TFzi"]')))

for i, element in enumerate(container, start=1):
    artist = element.find_element(By.CSS_SELECTOR, 'td[class^="title_"]> a').text
    print(f"Artista {i}: {artist}")

driver.quit()
python
  • 1 1 respostas
  • 22 Views

1 respostas

  • Voted
  1. Best Answer
    Ajeet Verma
    2023-08-02T20:52:11+08:002023-08-02T20:52:11+08:00

    Você deve tentar desta forma:

    from selenium.webdriver import Chrome
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    driver = Chrome()
    wait = WebDriverWait(driver, 10)
    
    url = "https://www.discogs.com/it/master/103917-The-Sound-Man-Featuring-Mercy-The-Factory"
    driver.get(url)
    
    title = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'h1[class^="title_"]'))).text
    print(f"Artista 1: {title}")
    
    container = wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, 'table[class^="tracklist_"]>tbody>tr')))
    
    for i, element in enumerate(container, start=1):
        artist = element.text
        print(f"Testo elemento {i}: {artist}")
    

    saída:

    Artista 1: The Sound Man Featuring Mercy (3) – The Factory
    Testo elemento 1: The Factory (Original Mix)
    Testo elemento 2: The Factory (Bass Dub)
    Testo elemento 3: The Factory (Junior's Factory Dub)
    Testo elemento 4: The Factory (Sexapella)
    Testo elemento 5: The Factory (Klubb Kidz Flava Dub)
    Testo elemento 6: The Factory (Klubb Kidz School Dub)
    Testo elemento 7: The Factory (Duke's Massive Blast)
    
    • 0

relate perguntas

  • Conda quebra ao ativar o ambiente -- CommandNotFoundError: Nenhum comando 'conda conda'

  • Documentação do Notepad++ e Python

  • SCons construídos com desenvolvimento gcc8

  • Matplotlib - Erro de instalação do mapa base

  • pip não vai atualizar ou instalar módulos corretamente

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Como posso reduzir o consumo do processo `vmmem`?

    • 11 respostas
  • Marko Smith

    Baixar vídeo do Microsoft Stream

    • 4 respostas
  • Marko Smith

    O Google Chrome DevTools falhou ao analisar o SourceMap: chrome-extension

    • 6 respostas
  • Marko Smith

    O visualizador de fotos do Windows não pode ser executado porque não há memória suficiente?

    • 5 respostas
  • Marko Smith

    Como faço para ativar o WindowsXP agora que o suporte acabou?

    • 6 respostas
  • Marko Smith

    Área de trabalho remota congelando intermitentemente

    • 7 respostas
  • Marko Smith

    O que significa ter uma máscara de sub-rede /32?

    • 6 respostas
  • Marko Smith

    Ponteiro do mouse movendo-se nas teclas de seta pressionadas no Windows?

    • 1 respostas
  • Marko Smith

    O VirtualBox falha ao iniciar com VERR_NEM_VM_CREATE_FAILED

    • 8 respostas
  • Marko Smith

    Os aplicativos não aparecem nas configurações de privacidade da câmera e do microfone no MacBook

    • 5 respostas
  • Martin Hope
    Vickel O Firefox não permite mais colar no WhatsApp web? 2023-08-18 05:04:35 +0800 CST
  • Martin Hope
    Saaru Lindestøkke Por que os arquivos tar.xz são 15x menores ao usar a biblioteca tar do Python em comparação com o tar do macOS? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh Como posso reduzir o consumo do processo `vmmem`? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Pesquisa do Windows 10 não está carregando, mostrando janela em branco 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    andre_ss6 Área de trabalho remota congelando intermitentemente 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney Por que colocar um ponto após o URL remove as informações de login? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension Ponteiro do mouse movendo-se nas teclas de seta pressionadas no Windows? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca Todos os meus complementos do Firefox foram desativados repentinamente, como posso reativá-los? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK É possível criar um código QR usando texto? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 Altere o nome da ramificação padrão do git init 2019-04-01 06:16:56 +0800 CST

Hot tag

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve