当前位置: 首页 > 知识库问答 >
问题:

python、chrome驱动程序错误

宋华美
2023-03-14

我有这个文件test.py:

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
driver = webdriver.Chrome(chrome_options=options)
driver.get("https://www.google.com")
print(driver.page_source)
driver.quit()

我想使用此python代码从页面获取页面源。我使用的是chrome驱动程序selenium和python。但是当我启动这个脚本时,我遇到了这个错误:

 File "test2.py", line 8, in <module>
    driver = webdriver.Chrome(chrome_options=options)
  File "/usr/local/python3/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/local/python3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/python3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/python3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/python3/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot create temp dir for user data dir

我在互联网上尝试了几乎所有的解决方案,但每次我遇到其他错误时,有人知道我在这种情况下应该怎么做吗?有人建议我如何解决这个问题吗?

共有2个答案

严俊彦
2023-03-14

尝试设置路径驱动程序,如下所示......使用此命令定位:chrome驱动程序在哪里

from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.chrome.options import Options


chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('/usr/bin/chromedriver',chrome_options=chrome_options)
宦博雅
2023-03-14

确保您安装了正确的chrome浏览器并支持正确的chrome驱动程序版本,这里是一些代码编辑建议

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.headless = True
options.add_argument('--disable-gpu')

driver = webdriver.Chrome(options=options)
driver.get("https://www.google.com")
print(driver.page_source)
driver.quit()
 类似资料:
  • 当我完成自动化后,Chrome Web驱动程序仍在后台运行,是否可以自动关闭它,而无需通过任务管理器执行?

  • 问题内容: 我正在尝试运行一个ruby文件,该文件将使用seleniumwebdriver启动chrome驱动程序。我有selenium独立服务器2.35.0。和chromedriver可执行文件已安装。我正在通过运行服务器来启动 两个会话正在启动,chrome驱动程序无法启动。 这是在我使用以下文件运行文件之后 我对此并不陌生,无法找出问题所在。而且,我也试图让它无头运行,所以我正在运行Xvfb

  • 我试图运行一个ruby文件,这将启动chrome驱动程序使用selenium WebDriver。我有selenium独立服务器2.35.0。和chromedriver可执行文件安装。我通过运行来启动服务器, 这是在我使用 我对此很陌生,不知道哪里出了问题。我也试图无头运行它,所以我有Xvfb运行。有人能帮我指出我犯的错误并启动chromedriver吗? 更新: 谁能帮我弄清楚出了什么问题吗?

  • 我假设Selenium打开的chrome浏览会话将与google chrome本地安装相同。但是当我尝试在这个网站上搜索时,即使只是用selenium打开它并手动控制搜索过程,我会得到一个错误信息,当我使用常规chrome与我自己的个人资料或在incognito窗口中搜索结果返回良好。每当我搜索这个问题,我发现结果指出鼠标移动或点击模式提供它。但情况并非如此,因为我在打开浏览器后尝试手动控制。ht

  • 当我尝试用Selenium 3.14、3.13或3.12启动WebDriver时,我得到 “org.openqa.selenium.remote.UnreachableBrowserException:无法启动新会话。可能的原因是远程服务器的地址无效或浏览器启动失败。”错误。 我可以用旧的Selenium版本运行测试而没有错误。我已经设置了环境变量(例如webdriver.chrome.drive

  • 我试图运行一个项目在硒与铬驱动程序,但我没有使用它一个月后(是一个更新到铬)。当我运行这个项目时,它会打开浏览器,然后立即关闭。 我收到以下错误: Traceback(最近一次调用最后一次):文件"C:\用户\maorb\OneDrive\Desktop\Maor\python\serethd\tvil_arthur.py",第27行,在驱动程序=webDrive中。Chrome()File"C: