Python-SeleniumChromeWebDriver不';我们没有像CDM这样的组件

Python-SeleniumChromeWebDriver不';我们没有像CDM这样的组件,python,selenium,chrome-web-driver,Python,Selenium,Chrome Web Driver,我正在尝试使用Selenium打开一个页面,然后转到Netflix,打开一个视频并播放。一旦我真正进入视频,我就无法加载它,因为我得到了错误: 缺少组件。。。请访问chrome://components,找到CDM组件 什么时候去chrome://components,没有安装任何组件。如果我像在Selenium中那样定期打开Chrome并浏览视频,我就可以播放它了。当我到达chrome://components 在普通铬合金中,有更多的成分。我正试图找出如何导入我的正常Chrome设置,但我似

我正在尝试使用Selenium打开一个页面,然后转到Netflix,打开一个视频并播放。一旦我真正进入视频,我就无法加载它,因为我得到了错误:

缺少组件。。。请访问chrome://components,找到CDM组件


什么时候去chrome://components,没有安装任何组件。如果我像在Selenium中那样定期打开Chrome并浏览视频,我就可以播放它了。当我到达chrome://components 在普通铬合金中,有更多的成分。我正试图找出如何导入我的正常Chrome设置,但我似乎不明白。我尝试过使用ChromeOptions和DesiredCapabilities.CHROME,但无法使其正常工作。我也找不到DesiredCapabilities.CHROME字典中所有项目的文档。我希望,一旦我能够将正常的Chrome设置添加到webdriver版本中,我就能够通过Selenium Chrome webdriver加载Netflix视频。

至少在OS X上可以工作。确保在工作目录中有正确的可执行文件

from selenium import webdriver

def buildDriver():
    options = webdriver.ChromeOptions()
    args = ['--user-data-dir=./ChromeProfile',
            '--disable-session-crashed-bubble',                
            '--disable-save-password-bubble',
            '--disable-permissions-bubbles',
            '--bwsi',
            '--incognito',
            '--disable-extensions']

    options.add_experimental_option('excludeSwitches', ['disable-component-update',
                                                        'ignore-certificate-errors'])
    for arg in args:
        options.add_argument(arg)

    chromedriver = './chromedriver'
    return webdriver.Chrome(chromedriver, chrome_options=options)


if __name__ == '__main__':
    driver = buildDriver()
    driver.get('chrome://components/')

我不太清楚为什么这个答案会被打下标记,因为它准确地回答了问题。

这并不是完整的解决方案,但我认为如果使用Chrome的默认用户目录并排除
禁用组件更新开关,组件将被正确加载。您可以找到不同平台的Chrome默认用户目录的路径*

例如,在Mac OS X上,执行以下操作:

options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['disable-component-update'])
options.add_argument('--user-data-dir=~/Library/Application\ Support/Google/Chrome/')

driver = webdriver.Chrome(chrome_options=options)

driver.get('chrome://components/')
你应该在那里看到

如果我能为自定义用户目录找到一种方法,我会更新它

*请注意,
Default
将自动添加到路径的末尾,因此您可以看到,我没有在传递给selenium的用户数据目录末尾包含
Default

更新1: 好啊如果您想使用自定义用户目录,我有一个[hacky]解决方案。排除
--disable component update
开关将为您加载组件,但不会完全加载。如果您转到
chrome://components
您将看到组件在那里,但它们都有
版本=0.0.0.0
,您需要单击更新按钮。下面是单击更新按钮的简单循环:

options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['disable-component-update'])
options.add_argument('--user-data-dir=path/to/your/dir')

driver = webdriver.Chrome(chrome_options=options)

driver.get('chrome://components/')

components = driver.find_elements_by_class_name('button-check-update')
for c in components:
    try:
        c.click()
    except:
        pass

请注意
尝试除此之外的操作
。您需要它,因为当您尝试单击某些隐藏按钮时,它们会引发异常。

此处已回答此问题:@Chainik,您链接的答案不是有效答案。至少不是python代码段。它构建WebDriver,但WebDriver实际上并不排除该标志。或者需要做其他事情,因为同样的错误出现了。只是提醒一下。我会发布准确的工作代码作为新答案。如果它对你不起作用,你需要更具体地帮助确定原因。@Chainik,我在这里发布了我的答案,以防其他人有同样的问题: