python - WebDriverException : Service U:/Scraping/chromedriver. exe 意外退出。状态代码为:1,同时使用 Chrome 和 Python

标签 python google-chrome selenium selenium-webdriver selenium-chromedriver

我一直在努力让 webdriver 在工作中与 Chrome 中的 Python 一起工作,但是尽管一天中的大部分时间都在进行故障排除,但我终究还是无法找出问题所在。

我已将 chromedriver 解压缩到我正在使用的文件夹中。我尝试将 executable_path 参数与 chromedriver 一起使用。我已尝试更新 chromedriver 中的选项以定向到 Chrome.exe 文件。

代码如下。非常简单。 'url' 有一个来自代码前面的地址,我没有在此处包含 - 无论如何,脚本甚至都没有做到这一点。

from selenium import webdriver

driver = webdriver.Chrome(executable_path = 'U:/Scraping/chromedriver.exe')
driver.get(url)

错误:

    Traceback (most recent call last):

  File "<ipython-input-67-db2ce2aa7cdf>", line 1, in <module>
    runfile('U:/Scraping/Project.py', wdir='U:/Scraping')

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "U:/Scraping/Project.py", line 14, in <module>
    driver = webdriver.Chrome(executable_path = 'U:/Scraping/chromedriver.exe')

  File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__
    self.service.start()

  File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
    self.assert_process_still_running()

  File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\common\service.py", line 111, in assert_process_still_running
    % (self.path, return_code)

WebDriverException: Service U:/Scraping/chromedriver.exe unexpectedly exited. Status code was: 1

最佳答案

同样的错误。我的问题是我在公司共享驱动器上安装了 chromedriver.exe。某些防火墙或安全设置可能会阻止 python 访问该远程位置的可执行文件。

我在本地制作了 chromedriver.exe 并且它工作了。

关于python - WebDriverException : Service U:/Scraping/chromedriver. exe 意外退出。状态代码为:1,同时使用 Chrome 和 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50844954/

相关文章:

python - 在 RobotFramework 中执行测试后,有没有办法让浏览器窗口保持打开状态?

Python selenium 绑定(bind),挑选 <td> 元素

python - 使用 Python 计算列表中的字符串数

python - 在 Python 中分解三阶张量

html - Chrome 和 Safari 突然在完全错误的位置显示我的网络字体 <h1>

html - 如何强制下载的 gzip 数据 URI 的文件扩展名?

python - 使用 python inspect 查看函数中的局部变量

javascript - 仅允许来 self 的 chrome 扩展程序的请求

selenium - 如何避免 "Element is not currently visible and so may not be interacted with "Selenium Webdriver

javascript - Selenium:如何使 RemoteDriver 始终附加到当前浏览器选项卡?