javascript - 'chromedriver' 可执行文件需要在 PATH 中,但它已经存在
问题描述
我想用 Python向这个网站发送消息。
也就是说,使用 python 执行以下操作:
这就是我使用 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
虽然我已经在 PATH 中添加了它:
我是 javascript 学习者。如果您有技巧和时间来展示如何在 Javascript 中回答问题,我总是很乐意学习 :)
解决方案
chromedriver 需要位于 python 脚本的路径中,或者您需要将其添加到驱动程序中:
driver_path = 'Path\to\your\Driver'
driver = webdriver.Chrome(executable_path = driver_path)
webdriver.Firefox()
如果你谈论,你为什么要使用Chrome
?
推荐阅读
- r - 代码在函数之外工作,但不在函数内部
- vba - 通过 For 循环更改 UserForm 元素的可见性
- flutter - 如何使小部件的高度最多为 X 像素?
- tableau-api - Tableau 使用前几个月计算的度量
- python - 无法将预处理数据作为 csv 保存到 s3 存储桶中的文件夹
- excel - Excel2016:根据多个条件生成 ID(无 VBA)
- javascript - 未捕获的类型错误:无法读取未定义的属性“muiName”
- spring-boot - 基于另一个创建 paketo builder
- android - 预览中的Android复合视图不显示高度或内容
- android - 单击链接时未启动 InstantApp