chrome driver
在尝试部署using--user-data-dir
和--profile-directory
from the user on时,我意识到了一些非常奇怪的事情Python 3.9.7
,见下文:
如果编译以下代码:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
opt = Options() #the variable that will store the selenium options
opt.add_argument('--user-data-dir='+r'C:\Users\ResetStoreX\AppData\Local\Google\Chrome\User Data') #Add the user data path as an argument in selenium Options
opt.add_argument('--profile-directory=Default') #Add the profile directory as an argument in selenium Options
s = Service('C:/Users/ResetStoreX/AppData/Local/Programs/Python/Python39/Scripts/chromedriver.exe')
driver = webdriver.Chrome(service=s, options=opt)
driver.get('https://opensea.io/login?referrer=%2Faccount')
您使用相应的--user-data-dir
and成功获得了一个 chrome 驱动程序实例--profile-directory
:
现在,在使用以下代码杀死所有 chrome 驱动程序实例后 cmd
:
taskkill /F /IM chromedriver.exe
然后编译这个其他代码:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
opt = Options() #the variable that will store the selenium options
path = input('Introduce YOUR profile path:')
opt.add_argument('--user-data-dir='+fr'"{path}"') #Add the user data path as an argument in selenium Options
opt.add_argument('--profile-directory=Default') #Add the profile directory as an argument in selenium Options
s = Service('C:/Users/ResetStoreX/AppData/Local/Programs/Python/Python39/Scripts/chromedriver.exe')
driver = webdriver.Chrome(service=s, options=opt)
driver.get('https://opensea.io/login?referrer=%2Faccount')
最后输入:C:\Users\ResetStoreX\AppData\Local\Google\Chrome\User Data
作为输入
你得到这个错误:
WebDriverException:未知错误:无法删除旧的 devtools 端口文件。可能“C:\Users\ResetStoreX\AppData\Local\Google\Chrome\User Data”中给定的用户数据目录仍附加到正在运行的 Chrome 或 Chromium 进程
为什么会这样?
不是opt.add_argument('--user-data-dir='+fr'"{path}"')
传递此用户数据路径的有效方式:
path = C:\Users\ResetStoreX\AppData\Local\Google\Chrome\User Data
?