python - 将扩展与 Google Chrome Selenium 驱动程序一起使用

标签 python google-chrome selenium selenium-webdriver

我正在尝试像这样添加我的扩展:

from selenium.webdriver.chrome.options import Options
import os
executable_path = "C:/Chrome/chromedriver.exe"
os.environ["webdriver.chrome.driver"] = executable_path
chrome_options = Options()
chrome_options.add_extension('C:/Users/Wilson/AppData/Local/Google/Chrome/User Data/Default/Extensions')

driver = webdriver.Chrome(executable_path=executable_path, chrome_options=chrome_options)

但出现以下错误:

Traceback (most recent call last):
  File "C:/Users/Wilson/Dropbox/xxx.py", line 77, in <module>
    driver = webdriver.Chrome(executable_path=executable_path, chrome_options=chrome_options)
  File "C:\Python33\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 55, in __init__
    desired_capabilities = options.to_capabilities()
  File "C:\Python33\lib\site-packages\selenium\webdriver\chrome\options.py", line 140, in to_capabilities
    chrome_options["extensions"] = self.extensions
  File "C:\Python33\lib\site-packages\selenium\webdriver\chrome\options.py", line 76, in extensions
    file_ = open(ext, 'rb')
PermissionError: [Errno 13] Permission denied: 'C:/Users/Wilson/AppData/Local/Google/Chrome/User Data/Default/Extensions'

不太确定我做错了什么。任何帮助将不胜感激。

最佳答案

    chop = webdriver.ChromeOptions()
    chop.add_argument('load-extension=path/to/extension')

用你想要的扩展试试这个,看看它是否仍然给你同样的错误

这是python的语法

关于python - 将扩展与 Google Chrome Selenium 驱动程序一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22130671/

相关文章:

python - 如何使用OpenCV在视频上绘制尾线

python - Tensorflow CNN 模型出现错误 "NaN loss during training."

python - 使用 pygtk 运行多个进程并捕获 python 中的输出

css - Chrome 自动刷新 css/less 更改

java - Robot框架如何在两台不同的机器上实现并行测试执行?

java - 登录过程: Not read my else statement in selenium

python - 如何在python中使用boto3查询cloudwatch日志

css - chrome 中的第二个 float div 在第一个 div 之前清除

visual-studio - 使用 chrome 和 visual studio.net 调试 asp.net - 与 IE 相比非常慢

java - 无法在Windows 8中安装maven