我的系统是win10,python是用Anacoda安装的,通过pip安装了selenium 后使用Chromedriver发现报错,pip安装selenium如下:
1
|
pip install selenium |
报错具体如下:
driver=webdriver.Chrome() Traceback (most recent call last): File "D:\app\Anaconda\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start stdin=PIPE) File "D:\app\Anaconda\lib\subprocess.py", line 947, in __init__ restore_signals, start_new_session) File "D:\app\Anaconda\lib\subprocess.py", line 1224, in _execute_child startupinfo) FileNotFoundError: [WinError 2] 系统找不到指定的文件。 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "D:\app\Anaconda\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__ self.service.start() File "D:\app\Anaconda\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
selenium操作chrome浏览器需要有ChromeDriver驱动来协助。
解决办法:
1.下载Chromedriver,网盘:https://pan.baidu.com/s/1c3KLRJa
2.把Chromedriver解压到D:\app\Anaconda\Scripts\下,重新运行命令即可打开Chromedriver
在运行了
driver=webdriver.Chrome() driver.get('www.baidu.com')
之后出现报错:
>>> driver.get('m.weibo.com') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "D:\app\Anaconda\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 324, in get self.execute(Command.GET, {'url': url}) File "D:\app\Anaconda\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute self.error_handler.check_response(response) File "D:\app\Anaconda\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: chrome not reachable (Session info: chrome=63.0.3239.132) (Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 10.0.16299 x86_64)
原因是打开的域名一定要加前http://,改正后如下: