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")
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)
这解决了我的问题。(结束时删除默认值)
Chrome_Options
已弃用。改用options
这个答案很简单,而且可以自我解释。
正如@MadRabbit所说,在地址栏中键入
chrome://version/
,以查找chrome配置文件数据的路径。C:\Users\pc\AppData\Local\Google\Chrome\User Data\Default
/Users/user/Library/Application Support/Google/Chrome/Default
中似乎是这样的因此,您所要做的就是从概要文件路径中删除最后一部分
。Default
这就是它最终为我工作的原因。
要查找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将为其创建新的配置文件和目录。
相关问题 更多 >
编程相关推荐