javascript - “chromedriver”可执行文件需要位于 PATH 中,但它已经存在

标签 javascript python python-3.x

我想发消息给 this website使用Python。

也就是说使用 python 执行以下操作:

introducir la descripción de la imagen aquí

这就是我使用 Selenium 尝试以下脚本的原因:

api_location = 'http://iphoneapp.spareroom.co.uk'
api_search_endpoint = 'flatshares'
api_details_endpoint = 'flatshares'

location = 'http://www.spareroom.co.uk'
details_endpoint = 'flatshare/flatshare_detail.pl?flatshare_id='
def contact_room(self, room_id):
    url = '{location}/{endpoint}/{id}?format=json'.format(location=self.api_location, endpoint=self.api_details_endpoint, id=room_id)
    from selenium import webdriver

    driver = webdriver.Chrome()
    # Go to your page url
    driver.get(url)
    # Get button you are going to click by its id ( also you could use find_element_by_css_selector to get element by css selector)
    button_element = driver.find_element_by_id('button id')
    button_element.click()

但它返回:

C:\Users\antoi\Documents\Programming\projects\roomfinder>python test_message.py
Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "C:\Python36\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "C:\Python36\lib\subprocess.py", line 997, 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 "test_message.py", line 21, in <module>
    contact_room(13829371)
  File "test_message.py", line 14, in contact_room
    driver = webdriver.Chrome()  # Optional argument, if not specified will search path.
  File "C:\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 83, 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

虽然我已经将其添加到路径中:

introducir la descripción de la imagen aquí

我是 javascript 学习者。如果您有技巧和时间来展示如何用 Javascript 回答问题,我总是很乐意学习:)

最佳答案

chromedriver 需要位于 python 脚本的路径中,或者需要将其添加到驱动程序中:

driver_path = 'Path\to\your\Driver'
driver = webdriver.Chrome(executable_path = driver_path)

如果您谈论 Chrome,为什么还要使用 webdriver.Firefox()

关于javascript - “chromedriver”可执行文件需要位于 PATH 中,但它已经存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58745668/

相关文章:

javascript - 实现用于输入数学公式的 GUI 的简单方法?

python : How to detect any changes in the screen

python - ModelForm 的额外字段没有标签,不会在 InlineModelAdmin 中呈现

python-3.x - IndexError : index 43462904 is out of bounds for size 43462904

python - 使用 ffmpeg 从 python openCV 流式传输图像

javascript - Django 无法从 HTML 模板加载 JS 文件

javascript - Twitter 时间轴小部件在中型设备上消失(Bootstrap)

javascript - 使用纯 JavaScript 检索待处理的 AJAX 请求数

python - 在 python 3 中遍历枚举时,并非所有元素都出现

python-3.x - 如何通过pyarrow使用用户定义的模式编写Parquet