Python Selenium Chrome Webdriver [英] Python Selenium Chrome Webdriver

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

问题描述

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

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-32\lib\site-packages\selenium\webdriver\common\service.py",
 line 74, in start
     stdout=self.log_file, stderr=self.log_file)   File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 707, in __init__
     restore_signals, start_new_session)   File "C:\Program Files (x86)\Python36-32\lib\subprocess.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-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py",
line 62, in __init__
   self.service.start()   File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.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\to\chromedriver.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 Webdriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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