from selenium import webdriver
import time
option = webdriver.ChromeOptions()
option.add_argument("--user-data-dir=C:\\Users\\Beck\\AppData\\Local\\Google\\Chrome\\User Data")
#Chrome浏览器网址栏输入:chrome://version/,在个人资料路径后找到
driver = webdriver.Chrome(chrome_options=option)
driver.get("https://www.cnblogs.com")
要事先关闭所有已打开的chrome浏览器!!!
经查阅资料得知,网上也确实有此情况的介绍,
见《Selenium chromedriver hangs if I specify user-data-dir in Chrome options》:
“The only one client could be connected to a debugger in one time. So, to fix the issue, when we want to enter to a user profile using a debugger - to avoid chromedriver hangs trying to connect to the debugger, we must close an existing Chrome session”
翻译为:只有一个客户端可以一次连接到调试器。所以,为了解决这个问题,当我们想要使用调试器进入用户配置文件为了避免chromedriver挂起试图连接到调试器,我们必须关闭一个现有的Chrome会话。