【问题标题】:Python Selenium Traceback (most recent call last):Python Selenium Traceback(最近一次调用最后一次):
【发布时间】:2020-03-24 03:49:56
【问题描述】:

我正在尝试将 selenium 用于 python 网络爬虫,但是当我尝试运行该程序时出现以下错误:

"/Applications/Python 3.8/IDLE.app/Contents/MacOS/Python" "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 52548 --file /Users/xxxx/git/python/python_crawler_example_01/naver_crawling.py
pydev debugger: process 3004 is connecting

Connected to pydev debugger (build 192.7142.56)
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home


Process finished with exit code 1

这是我的错误代码:

from selenium import webdriver
from bs4 import BeautifulSoup as bs

import time
import os, sys

driver = webdriver.Chrome()

time.sleep(2)

driver.close()

我正在使用 macOS 和 pycharm

https://i.stack.imgur.com/dJtFi.jpg

【问题讨论】:

  • 您能否在driver = webdriver.Chrome() 之前添加print(os.environ['PATH']) 并检查它是否确实包含您的chromedriver 的路径?
  • 结果值与我的路径不对应。我该怎么办?

标签: python macos selenium web-scraping pycharm


【解决方案1】:

你应该把你的网络驱动程序的路径

例子:(如果在同一目录下)

driver = webdriver.Chrome(executable_path = "/chromedriver.exe")

【讨论】:

  • 再次下载 chromedriver.exe 可能会有帮助
  • 我做到了。但它不起作用。而且,我正在使用 macos。
  • 我没有在 mac os 上试过,但你应该看看这个链接edureka.co/community/52315/…
  • 请检查chrome版本和chrome驱动版本
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-08-19
  • 1970-01-01
  • 1970-01-01
  • 2016-05-31
  • 2022-01-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多