【发布时间】:2018-07-25 19:41:23
【问题描述】:
运行一个快速脚本
from selenium import webdriver
path = r"C:/Users/andre/Desktop/chromedriver.exe"
driver = webdriver.Chrome(path)
driver.get('https://www.google.ca')
输出是
andrefu@LAPTOP-1011FFMG:/mnt/c/Users/andre/Desktop/Pardee Lab$ python3 Scrape_RNAfold.py
Traceback (most recent call last):
File "/home/andrefu/anaconda3/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/home/andrefu/anaconda3/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/home/andrefu/anaconda3/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/andre/Desktop/chromedriver.exe': 'C:/Users/andre/Desktop/chromedriver.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "Scrape_RNAfold.py", line 7, in <module>
driver = webdriver.Chrome(path)
File "/home/andrefu/anaconda3/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
self.service.start()
File "/home/andrefu/anaconda3/lib/python3.6/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.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
我的 chromedriver.exe 在我的桌面 所以,我真的不知道为什么它说 chromedriver 不起作用。
我尝试了不同的路径,例如
path = 'C:\Users\andre\Desktop\chromedriver.exe'
path = 'C:\Users\andre\Desktop'
path = 'C:/Users/andre/Desktop/chromedriver.exe'
path = 'C:/Users/andre/Desktop'
即使将我的 chromedriver 与我的代码 Scrape_RNAfold.py 放在同一个文件夹中,也可以使用完整路径名和 driver = webdriver.Chrome() 运行它。
我还尝试了在字符串之前使用原始 'r' unicode 并且不使用它并使用单引号和双引号。有人可以帮我确定我哪里出错了吗?
【问题讨论】:
-
尝试将其与 Python3 可执行文件放在同一文件夹中并用作
driver = webdriver.Chrome() -
@Andersson 感谢您抽出宝贵时间,在原始帖子中您可以看到我已经尝试过了。这里是my output
-
没有。我的意思不是和你的脚本在同一个文件夹中,而是在同一个文件夹中
python3.exe -
@Andersson 对此感到抱歉,我正在使用 WSL,所以我的 python3.exe 一直在我的 /home 中。这里是my output
-
@Andersson 我不知道把它放到我的 python3.exe 中做了什么,但它一直给我 Invalid 参数。注意:它现在不允许我做任何事情,我尝试了
pip freeze | grep splinter,它给了我一个无效的论点! (哦,不,我不知道我做了什么......)我现在从那个文件夹中删除了 chromedriver.exe。
标签: python-3.x selenium selenium-webdriver selenium-chromedriver windows-subsystem-for-linux