简体   繁体   English

Selenium Mac Google Chrome 上的 Google Colab 中的 Webdriver 错误

[英]Selenium Webdriver error in Google Colab on Mac Google Chrome

I'm following a scraping tutorial from GeeksForGeeks below: https://colab.research.google.com/drive/14kXYQCSGVye4bBKKExtuHOeq32bc4xbW?usp=sharing#scrollTo=UjB8J1L8s6kT我正在关注下面 GeeksForGeeks 的抓取教程: https://colab.research.google.com/drive/14kXYQCSGVye4bBKKExtuHOeq32bc4xbW?usp=sharing#scrollTo=UjB8J1L8s6kT

I'm working on a Macbook Pro in Google Colab via Chrome.我正在通过 Chrome 在 Google Colab 中开发 Macbook Pro。

When I get to the 4th command block where the path and driver are defined I get an error saying当我到达定义了路径和驱动程序的第 4 个命令块时,我收到一条错误消息

<ipython-input-33-bb59bfe38590>:2: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  driver = webdriver.Chrome(PATH)

And

During handling of the above exception, another exception occurred:

WebDriverException                        Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py in _start_process(self, path)
    211         except OSError as err:
    212             if err.errno == errno.ENOENT:
--> 213                 raise WebDriverException(
    214                     f"'{os.path.basename(self.path)}' executable needs to be in PATH. {self.start_error_message}"
    215                 )

WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home

What does this mean?这是什么意思? Do I need to link to webdriver on my local mac drive?我需要链接到本地 Mac 驱动器上的 webdriver 吗? Currently the command in the tutorial is:目前教程中的命令是:

PATH = "/Users/Edu/Desktop/VENV/chromedriver"
driver = webdriver.Chrome(PATH)

driver.get(url)

Do I need to replace this with the path to chromedriver in my files?我需要用文件中的 chromedriver 路径替换它吗? I tried replacing the path above with the below but it doesn't change anything:我尝试用下面的路径替换上面的路径,但它没有改变任何东西:

/Users/KD/Downloads/chromedriver

Tried the command below from the tutorial linked here: https://colab.research.google.com/drive/14kXYQCSGVye4bBKKExtuHOeq32bc4xbW?usp=sharing#scrollTo=UjB8J1L8s6kT从此处链接的教程尝试了以下命令: https://colab.research.google.com/drive/14kXYQCSGVye4bBKKExtuHOeq32bc4xbW?usp=sharing#scrollTo=UjB8J1L8s6kT

PATH = "/Users/Edu/Desktop/VENV/chromedriver"
driver = webdriver.Chrome(PATH)

driver.get(url)

You need to use Service .您需要使用Service
The following works:以下作品:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = Options()
options.add_argument("start-maximized")

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(service=webdriver_service, options=options)

url = 'your_link'
driver.get(url)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM