我最近遇到一个问题,在使用 Selenium 时,想要使用我的默认 chrome 浏览器配置文件,因此它已登录以及所有内容,但是当在谷歌上搜索时,它给了我一个基本上是这样的代码:
chrome_options = Options()
chrome_options.add_argument("[path to the profile]")
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=[path to the webdriver])
我收到的错误是:
NameError: name 'Options' is not defined
我该如何解决这个问题,也许有更好的方法来加载 Chrome 配置文件?
最佳答案
有两件事。可能您尚未导入 Options
所需的模块。因此,要使用 Options
实例,您必须包含以下导入
:
from selenium.webdriver.chrome.options import Options
此外,chrome_options
已弃用,您必须使用 options
代替。所以你的有效代码块将是:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("[path to the profile]")
driver = webdriver.Chrome(options=chrome_options, executable_path=[path to the webdriver])
关于python - 如何在Python Selenium中寻址 "Options is not defined error"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65960797/