WebDriverException:服务U:/Scraping/chromedriver.exe意外退出.状态码为:1(使用Chrome和Python时) [英] WebDriverException: Service U:/Scraping/chromedriver.exe unexpectedly exited. Status code was: 1 while working with Chrome and Python

查看:315
本文介绍了WebDriverException:服务U:/Scraping/chromedriver.exe意外退出.状态码为:1(使用Chrome和Python时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力使Webdriver在Chrome中使用Python,但尽管一天中大部分时间都在进行故障排除,但我一生都无法找出问题所在.

I've been trying to get the webdriver to work with Python in Chrome at work, but can't for the life of me figure out what's wrong, despite troubleshooting for most of the day.

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

I've unzipped chromedriver to the folder I'm working in. I've tried using the executable_path argument with chromedriver. I've tried updating the options within chromedriver to direct to the Chrome.exe file.

代码在下面.非常简单. "url"具有代码中较早版本的地址,我在此处未包括该地址-脚本甚至都无法做到这一点.

Code is below. Pretty straightforward. 'url' has an address from earlier in the code that I'm not including here - the script doesn't even make it that far anyways.

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

推荐答案

我与@rvictordelta有相似的经历.由于某种原因,我无法再通过python编辑驱动程序所在的位置,并且当我更改为共享驱动器进行工作时也无法正常工作.最后,在下面使用此代码.这个版本很好,因为它会检查最新的chrome驱动程序.如果驱动程序存在,则仅使用它,否则,它将下载并安装它.

I had a similar experience to @rvictordelta. For some reason I could no longer edit the location where the driver was through python, and when I changed to a shared drive for work that wouldn't work as well. Finally, used this code below. This version is good because it checks for the most up to date chrome driver. If the driver exists it simply uses it, but if not it will download and install it.

custom_path=r'C:\Users\username'

driver = webdriver.Chrome(ChromeDriverManager(path=custom_path).install(),options=chrome_options))

这篇关于WebDriverException:服务U:/Scraping/chromedriver.exe意外退出.状态码为:1(使用Chrome和Python时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆