Python Selenium Chrome 网络驱动程序 [英] Python Selenium Chrome Webdriver

查看:33
本文介绍了Python Selenium Chrome 网络驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始自动化这本无聊的东西,我正在尝试通过 python 打开一个 chrome 网络浏览器.我已经安装了 selenium 和

I'm beginning the automate the boring stuff book and I'm trying to open a chrome web browser through python. I have already installed selenium and

我已尝试运行此文件:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

browser = webdriver.Chrome()
browser.get('https://automatetheboringstuff.com')

但正因为如此,我得到了这个错误:

But because of that I get this Error:

Traceback (most recent call last):   File "C:Program Files
   (x86)Python36-32libsite-packagesseleniumwebdrivercommonservice.py",
 line 74, in start
     stdout=self.log_file, stderr=self.log_file)   File "C:Program Files (x86)Python36-32libsubprocess.py", line 707, in __init__
     restore_signals, start_new_session)   File "C:Program Files (x86)Python36-32libsubprocess.py", line 990, in _execute_child
     startupinfo) FileNotFoundError: [WinError 2] The system cannot find the file specified

在处理上述异常的过程中,又发生了一个异常:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):   File "C:/Program Files
(x86)/Python36-32/test.py", line 5, in <module>
    browser = webdriver.Chrome()   File "C:Program Files (x86)Python36-32libsite-packagesseleniumwebdriverchromewebdriver.py",
line 62, in __init__
   self.service.start()   File "C:Program Files (x86)Python36-32libsite-packagesseleniumwebdrivercommonservice.py",
line 81, in start
   os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: 'chromedriver'
  executable needs to be in PATH. Please see
https://sites.google.com/a/chromium.org/chromedriver/home

推荐答案

你需要指定你的chromedriver所在的路径.

  1. 从此处下载所需平台的 chromedriver.

将 chromedriver 放在系统路径或代码所在的位置.

Place chromedriver on your system path, or where your code is.

如果不使用系统路径,请链接您的 chromedriver.exe(对于非 Windows 用户,它只是称为 chromedriver):

If not using a system path, link your chromedriver.exe (For non-Windows users, it's just called chromedriver):

browser = webdriver.Chrome(executable_path=r"C:path	ochromedriver.exe")

(将 executable_path 设置为您的 chromedriver 所在的位置.)

(Set executable_path to the location where your chromedriver is located.)

如果您已将 chromedriver 放置在系统路径中,则只需执行以下操作即可快捷方式:

If you've placed chromedriver on your System Path, you can shortcut by just doing the following:

browser = webdriver.Chrome()

如果您运行的是基于 Unix 的操作系统,您可能需要在下载后更新 chromedriver 的权限以使其可执行:

If you're running on a Unix-based operating system, you may need to update the permissions of chromedriver after downloading it in order to make it executable:

chmod +x chromedriver

就是这样.如果您仍然遇到问题,可以在其他 StackOverflow 文章中找到更多信息:可以'不要为 Selenium 使用 chrome 驱动程序

That's all. If you're still experiencing issues, more info can be found on this other StackOverflow article: Can't use chrome driver for Selenium

这篇关于Python Selenium Chrome 网络驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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