我正在开始使用 Selenium for python 并有这个:
from selenium import webdriver
browser = webdriver.Chrome()
但是它给出了这个错误:
Traceback (most recent call last):
File "C:\Users\Bradley Jo\AppData\Local\Programs\Python\Python36\lib\site-
packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Users\Bradley
Jo\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 709, in
__init__
restore_signals, start_new_session)
File "C:\Users\Bradley
Jo\AppData\Local\Programs\Python\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 "C:\Users\Bradley Jo\Desktop\Project\app.py", line 3, in
<module>
browser = webdriver.Chrome()
File "C:\Users\Bradley Jo\AppData\Local\Programs\Python\Python36\lib\site-
packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__
self.service.start()
File "C:\Users\Bradley Jo\AppData\Local\Programs\Python\Python36\lib\site-
packages\selenium\webdriver\common\service.py", line 81, 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
[Finished in 1.0s]
有人知道如何解决这个问题吗?谢谢
最佳答案
对于 Windows:
- Check you have installed latest version of chrome browser
- If not, install latest version of chrome
- download the latest(or appropriate) version of chromedriver from here
- Paste the
chromedriver.exe
file in"<Install Dir>/Python27/Scripts"
Folder.
下面的代码现在应该可以工作:
from selenium import webdriver
driver = webdriver.Chrome()
关于python - browser = webdriver.Chrome() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47640949/