运行快速脚本
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,并使用单引号和双引号将其删除。有人可以帮我确定我要去哪里错吗?
答案 0 :(得分:0)
路径分隔符(即/
)和引号(即""
)之间似乎有些不匹配
您需要从ChromeDriver - WebDriver for Chrome下载最新的 ChromeDriver 并将其存储在系统中的任何位置。在 Windows操作系统上,解压缩二进制文件并执行以下操作:
\\
。 1}} " "
,即\
以及原始的" "
开关,如下所示。因此您的代码块将是:
r
答案 1 :(得分:0)
我发现使用driver = './chromedriver.exe'
是最有效的方法,而不必给出PATH