gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 20:10:26 24 4
gpt4 key购买 nike

我想发消息给 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com