我正在尝试制作一个可以在 youtube 上获取视频链接的程序,这是我的代码
video=Song_name
chromeOptions=Options()
chromeOptions.add_experimental_option("prefs{'download.default_directory':down_pth}")
driver=webdriver.Chrome(path+"/chromedriver.exe",options=chromeOptions)
wait=WebDriverWait(driver,3)
presence = EC.presence_of_element_located
visible = EC.visibility_of_element_located
driver.get("https://www.youtube.com/results?search_query=" + str(video))
wait.until(visible((By.ID, "video-title")))
driver.find_element_by_id("video-title").click()
print(driver.current_url)
url=driver.current_url
print(url)
此代码仅在 youtube 上的视频出现在列表中的第一个位置时才有效,否则如果某些广告出现在视频的(顶部)之前,它将失败。如何避免广告并直接播放视频?
Here is the image in which ads come on top of the video and I am not able to open video
如何解决这个问题?
最佳答案
我会导航到视频 URL 页面并使用 .SendKeys()
发送F6
键,它将完整地突出显示 URL。然后我会发送Ctrl + C
复制,你应该好好去!
关于python-3.x - 如何使用 selenium python 从 youtube 获取视频链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62800038/