【问题标题】:How to get link of video from youtube using selenium python如何使用 selenium python 从 youtube 获取视频链接
【发布时间】:2020-07-08 17:11:02
【问题描述】:

我正在尝试制作一个可以在 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

如何解决这个问题?

【问题讨论】:

    标签: python-3.x selenium web-scraping youtube selenium-chromedriver


    【解决方案1】:

    我会导航到视频 URL 页面并使用 .SendKeys()

    发送F6 键,它将完整地突出显示 URL。然后我会发送Ctrl + C 进行复制,你应该很高兴!

    【讨论】:

    • 你的想法不错,但是我的程序播放了许多结果中的第一个视频,那么如果我的程序播放广告并获取广告的 url 怎么办?
    • @SmitParmar 你怎么能从其他视频中表示主视频?
    猜你喜欢
    • 2022-12-12
    • 1970-01-01
    • 2016-07-22
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    相关资源
    最近更新 更多