例如,表示Windows目录的最佳方法是什么"C:\meshes\as"?我一直在尝试修改脚本,但它永远不会起作用,因为我似乎无法正确获取目录,我假设因为'\'扮演转义角色?
当我尝试让--user-data-dir当前用户使用 Selenium 启动 Chrome 时,出现以下错误:
File "C:\Program Files (x86)\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Program Files (x86)\Python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个错误?
python selenium google-chrome invalidargumentexception selenium-chromedriver
我一直在写的剧本一直工作得很好。我刚刚添加了该选项,因此它将使用此代码在 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')
Run Code Online (Sandbox Code Playgroud)
使用时,我收到此错误代码。
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'
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
python selenium google-chrome selenium-chromedriver chrome-profile
尽管我意识到这不是“好的”做法-我有一个用例,需要将Selenium驱动程序指向(连接)我的默认Chrome会话/配置文件。
我的默认个人资料在这里:
~/Library/Caches/Google/Chrome/Default
这是我当前的设置方式:(不起作用)
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=~/Library/Caches/Google/Chrome")
options.add_argument("--profile-directory=Default")
browser = webdriver.Chrome(options=options, executable_path=r"./chromedriver")
browser.get("http://google.com")
Run Code Online (Sandbox Code Playgroud)
我正在使用Chrome版本74.0.3729.169和chromedriver版本ChromeDriver 74.0.3729.6(这是兼容版本)。
Chrome打开后,我在Chrome的设置中看不到任何Cookie,因此很明显它没有指向我的默认会话。另外,我看到Selenium已经创建了一个目录(这似乎表示该目录无法连接到的会话)~/Library/Caches/Google/Chrome/Default。
如何将硒连接到默认的Chrome会话?这与正常打开Chrome浏览器时看到的会话相同。
我已经看过另一个问题,但是那里的答案无法解决如何将Selenium指向默认会话。另外-这是一个过时的问题-从那时起,Chrome和Chromedriver取得了很大进步。另外,这里的问题假定发布者能够连接到默认会话-我无法执行此操作,这表明此后Chromedriver / Chrome已经更改。这个问题也是针对Windows的-我在Mac上工作方式有所不同。
cookies selenium google-chrome session-cookies selenium-webdriver
我正在尝试使用默认用户使用 selenium python 库打开网页,脚本使用默认用户至关重要,但如果我的 chrome 浏览器已经打开脚本崩溃并给我这个错误:
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
Run Code Online (Sandbox Code Playgroud)
我已经尝试了这里给出的所有解决方案:
如果打开另一个 chrome 实例,Selenium chromedriver 将不会启动 URL
Selenium 不会在新选项卡中打开新 URL(Python 和 Chrome)
并阅读旧版 chromedriver 版本中存在错误,但已在 chrome 74(我正在使用)中修复:https : //github.com/SeleniumHQ/docker-selenium/issues/741
from selenium import webdriver
import time
from getpass import getuser
def run():
# Chrome driver path
chromedriver = r'C:\Users\user1\Downloads\chromedriver_win32\chromedriver_new.exe'
# Get chrome webdriver options and set open the browser as headless …Run Code Online (Sandbox Code Playgroud) python selenium google-chrome selenium-chromedriver chrome-profile
我正在尝试使用 selenium 在 python 中制作一个脚本,它将打开一个网站并单击一个按钮。问题是我必须先关闭 chrome,然后才能运行脚本,否则我会收到此错误:
Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
Run Code Online (Sandbox Code Playgroud)
有没有办法解决这个问题,这样我就不必在每次运行脚本之前关闭 chrome?
我的代码:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
PATH = "C:\Program Files (x86)\chromedriver.exe"
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:/Users/username/AppData/Local/Google/Chrome/User Data")
driver = webdriver.Chrome(executable_path=r'C:\Program Files (x86)\chromedriver.exe', chrome_options=options)
driver.get("https://disboard.org/sv/dashboard/servers")
link = driver.find_element_by_link_text("bump")
link.click()
Run Code Online (Sandbox Code Playgroud) python selenium google-chrome selenium-chromedriver chrome-profile
我正在尝试在 python 上使用 selenium 进行一些 chrome 自动化,并且我希望为 youtube 保存我的登录信息,这样我就不必自动化登录过程。我读到让 Chrome 读取我保存的信息的方法是使用该user-data-dir选项,但我无法让它工作。
我在这里查看了一些问题,例如this,它们似乎表明user-data-dirselenium for chrome中参数的正确用法是内部的配置文件路径:C:\Users\adassa\AppData\Local\Google\Chrome\User Data。如Default或Profile 1。我似乎无法使用这种路径获得预期的结果。对我有用的唯一路径是User Data文件夹本身。
所以当我这样做时:
chrome_options.add_argument("--user-data-dir=" + r'C:\\Users\\adassa\AppData\\Local\\Google\\Chrome\\User Data')
chrome 实例将打开,并使用为默认配置文件设置的首选项。但只有当我关闭 chrome 的所有其他实例时,它才能正常工作,否则会引发错误:invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
我认为这是由于我的手动 chrome 实例阻止访问该文件夹上的信息造成的,因为我正在使用它。我读到我可以创建一个新的 chrome 配置文件,这样它就不会与我通常使用的配置文件冲突,但是如果我在 chrome 上手动创建一个新的配置文件,并使用配置文件路径,如下所示:
chrome_options.add_argument("--user-data-dir=" + r'C:\\Users\\adassa\AppData\\Local\\Google\\Chrome\\User Data\\Profile 1')
新实例没有我保存到配置文件中的信息。即使我使用User Data\Default文件夹作为路径,也会发生这种情况。我还使用该选项尝试了不同的组合profile-dir,但没有成功。
阅读 …