我写的剧本一直很好用。我刚添加了该选项,因此它将使用此代码在chrome上打开配置文件。
options = webdriver.ChromeOptions
browser = webdriver.Chrome(executable_path=r"C:\Users\princess\AppData\Local\Programs\Python\Python36-32\chromedriver.exe", chrome_options=options)
options.add_argument(r'user-data-dir=C:\Users\princess\AppData\Local\Google\Chrome\User Data')
options.add_argument('--profile-directory=Profile 1')
使用时,我收到此错误代码。
C:\Users\Princess\Desktop>CHBO.py
Traceback (most recent call last):
File "C:\Users\Princess\Desktop\CHBO.py", line 12, in <module>
browser = webdriver.Chrome(executable_path=r"C:\Users\princess\AppData\Local\Programs\Python\Python36-32\chromedriver.exe", chrome_options=options)
File "C:\Users\Princess\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 59, in __init__
desired_capabilities = options.to_capabilities()
TypeError: to_capabilities() missing 1 required positional argument: 'self'
我该如何解决这个问题?
答案 0 :(得分:3)
要创建并打开新的 Chrome个人资料,您需要按照以下步骤操作:
获取系统中 profile-directory 的绝对路径,如下所示:
chrome://settings/
现在使用C:\\Users\\Otaku_Wiz\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2
方法通过选项的实例传递 profile-directory 的值以及用户数据 - dir 如下:
add_argument()
执行您的from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("user-data-dir=C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2")
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.co.in")
答案 1 :(得分:2)
您可以在options = Options()
options = webdriver.ChromeOptions()
或options = webdriver.ChromeOptions