Mad*_*bit 25 python selenium-chromedriver
因此,我想使用pythons webdriver打开其默认配置文件的chrome.我已经尝试了我能找到的所有东西,但我仍然无法让它发挥作用.谢谢您的帮助!
Mad*_*bit 56
这就是最终让它为我工作的东西.
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Path") #Path to your chrome profile
w = webdriver.Chrome(executable_path="C:\\Users\\chromedriver.exe", chrome_options=options)
Run Code Online (Sandbox Code Playgroud)
要查找chrome配置文件数据的路径,您需要输入chrome://version/地址栏.对于前者 我的显示为C:\Users\pc\AppData\Local\Google\Chrome\User Data\Default,在我必须排除的脚本中使用它,\Default\所以我们最终只有C:\Users\pc\AppData\Local\Google\Chrome\User Data.
此外,如果您想为selenium设置单独的配置文件:将路径替换为任何其他路径,如果它在启动时不存在,则chrome将为其创建新的配置文件和目录.
小智 21
我用“Yoannes Geissler”的答案解决了我的问题。
就我而言,我的个人资料被命名为“个人资料 2”
我的代码:
options = webdriver.ChromeOptions()
options.add_argument('--user-data-dir=C:/Users/GOD/AppData/Local/Google/Chrome/User Data')
options.add_argument('--profile-directory=Profile 2')
wd = webdriver.Chrome(options=options)
Run Code Online (Sandbox Code Playgroud)
下面的行解决了我的问题:
options.add_argument('--profile-directory=Profile 2')
Run Code Online (Sandbox Code Playgroud)
Nil*_*ker 10
这解决了我的问题.(最后删除默认值)
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=/home/username/.config/google-chrome")
cls.driver = webdriver.Chrome(options=options,
executable_path="./../ext/chromedriver")
Run Code Online (Sandbox Code Playgroud)
Chrome_Options不推荐使用.请options改用
只是分享对我有用的东西。使用默认的配置文件很复杂,chrome 总是崩溃。
from pathlib import Path
from selenium import webdriver
driver_path = Path("{}/driver/chromedriver75.exe".format(PATH_TO_FOLDER))
user_data_dir = Path("{}/driver/User Data".format(PATH_TO_FOLDER))
options = webdriver.ChromeOptions()
# TELL WHERE IS THE DATA DIR
options.add_argument("--user-data-dir={}".format(user_data_dir))
# USE THIS IF YOU NEED TO HAVE MULTIPLE PROFILES
options.add_argument('--profile-directory=Default')
driver = webdriver.Chrome(executable_path=driver_path, options=options)
driver.get("https://google.com/")
Run Code Online (Sandbox Code Playgroud)
通过执行此操作,Chrome 将创建该文件夹User Data并将所有数据保存在我想要的位置,并且可以轻松地将您的项目移动到另一台计算机。
这个答案非常简单且不言自明。
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
exec_path_chrome = "path/to/Google Chrome" #Do not use this path that is extracted from "chrome://version/"
exec_path_driver = "path/to/chromedriver"
ch_options = Options() #Chrome Options
ch_options.add_argument("user-data-dir = /path/to/Chrome Profile") #Extract this path from "chrome://version/"
driver = webdriver.Chrome(executable_path = exec_path_driver, options = ch_options) #Chrome_Options is deprecated. So we use options instead.
driver.get("https://stackoverflow.com/a/57894065/4061346")
Run Code Online (Sandbox Code Playgroud)
正如 @MadRabbit 所说,chrome://version/在地址栏中输入以查找 chrome 配置文件数据的路径。
C:\Users\pc\AppData\Local\Google\Chrome\User Data\Default/Users/user/Library/Application Support/Google/Chrome/Default因此,您所要做的就是从配置文件路径中删除最后一部分。Default
注意:请确保不要同时运行多个会话,以避免出现问题。
| 归档时间: |
|
| 查看次数: |
29072 次 |
| 最近记录: |