如何在Selenium Chrome Webdriver,Python中正确使用自定义配置文件

options_ = webdriver.ChromeOptions()
options_.add_argument("user-data-dir=C:\\Users\\Anton\\\\AppData\\Local\\Google\\Chrome\\User Data\\Default")
driver = webdriver.Chrome(executable_path='C:\chromedriver\chromedriver.exe',chrome_options=options_)

我正在尝试使用当前的Chrome配置文件来避免在自动化项目中出现验证码。

无济于事,Selenium拒绝加载除临时配置文件之外的任何其他配置文件。 我使用的语法不正确? 'chrome_options = options_'给了我一个弃用消息,但将其更改为'options = options_'并没有带来任何效果

编辑: Amit YR的评论解决了我最初的问题,Selenium现在使用正确的用户个人资料打开Chrome。

但是现在出现了一个新问题。浏览器打开后,脚本停止,并显示以下错误:

Traceback (most recent call last):
  File "C:\Users\Anton\Documents\pytho.py",line 24,in <module>
    driver = webdriver.Chrome(executable_path='C:\chromedriver\chromedriver.exe',options=options_)
  File "C:\Users\Anton\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py",line 81,in __init__
    desired_capabilities=desired_capabilities)
  File "C:\Users\Anton\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py",line 157,in __init__
    self.start_session(capabilities,browser_profile)
  File "C:\Users\Anton\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py",line 252,in start_session
    response = self.execute(Command.NEW_SESSION,parameters)
  File "C:\Users\Anton\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py",line 321,in execute
    self.error_handler.check_response(response)
  File "C:\Users\Anton\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py",line 242,in check_response
    raise exception_class(message,screen,stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use,please specify a unique value for --user-data-dir argument,or don't use --user-data-dir
XHLIZIMING 回答:如何在Selenium Chrome Webdriver,Python中正确使用自定义配置文件

由于chrome将默认设置添加到配置文件路径,因此从“ user-data-dir = C:\ Users \ Anton \\ AppData \ Local \ Google \ Chrome \ User Data \ Default”中删除默认设置。

您应该使用

options_.add_argument("user-data-dir=C:/Users/Anton/AppData/Local/Google/Chrome/User Data")
本文链接:https://www.f2er.com/3139956.html

大家都在问