J'ai fait un programme pour saisir un lien YouTube et saisissez-le sur un site Web, mais il n'est pas capable de trouver la boîte de saisie ... PLZ Dites-moi pourquoi
Traceback (most recent call last): File "e:\pranil\python\doing shit with python\songs downloader.py", line 17, in <module> search_bar = web.find_element_by_xpath('//*[@id="videoURL"]') File "C:\Users\Pranil.DESKTOP-TLQKP4G.000\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath return self.find_element(by=By.XPATH, value=xpath) File "C:\Users\Pranil.DESKTOP-TLQKP4G.000\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element 'value': value})['value'] File "C:\Users\Pranil.DESKTOP-TLQKP4G.000\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\Pranil.DESKTOP-TLQKP4G.000\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="videoURL"]"} (Session info: chrome=83.0.4103.116)
3 Réponses :
Le XPath que vous avez fourni pour trouver un élément ne semble pas fonctionner "" // [@ id = "videourl"] "" J'ai aussi ouvert une vidéo YouTube pour voir ce que vous cherchiez mais je ne pouvais pas Trouvez VideourL Si vous essayez d'obtenir l'URL, je vous recommande de vous connecter à Selenium, cliquez sur le bouton Partager et saisissez le lien à partir de là. P>
import time from selenium import webdriver import pyautogui as auto url = 'https://www.youtube.com/results?search_query=closer+8d' web = webdriver.Chrome('./chromedriver') web.get(url) time.sleep(3) link = web.find_element_by_id('video-title') link = link.get_attribute('href') web.execute_script("window.open('https://www.youtubemp3.pro/en2', 'new_window')") web.switch_to_window(web.window_handles[-1]) ylink = web.find_element_by_id("videoURL") ylink.click() ylink.send_keys(link) submit = web.find_element_by_name("submitForm") submit.click() you do not have to use pyautogui it will work better if you use seleniu
Essayez de trouver l'élément avec ID ID.
import time from selenium import webdriver url = 'https://www.youtube.com/results?search_query=closer+8d' web = webdriver.Chrome('../assets/chromedriver') web.get(url) time.sleep(3) link = web.find_element_by_id('video-title') link = link.get_attribute('href') web.get('https://www.youtubemp3.pro/en2/') time.sleep(3) search_bar = web.find_element_by_id('txt-url') search_bar.click() search_bar.send_keys(link)