Wei*_*ung 3 selenium google-chrome web-crawler python-3.x selenium-webdriver
当我使用硒来控制Chrome时,我遇到了麻烦.这是我的代码:
from selenium import webdriver
driver = webdriver.Chrome()
Run Code Online (Sandbox Code Playgroud)
当我尝试操作它时,它首先成功运行,Chrome在屏幕上弹出.然而,它在几秒钟后关闭.

Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
driver = webdriver.Chrome('C:\Program Files (x86)\Google\Chrome\chrome.exe')
File "C:\Users\35273\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
self.service.start()
File "C:\Users\35273\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 86, in start
self.assert_process_still_running()
File "C:\Users\35273\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 99, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service C:\Program Files (x86)\Google\Chrome\chrome.exe unexpectedly exited. Status code was: 0
Run Code Online (Sandbox Code Playgroud)
您需要提供chromedriver的路径...从http://chromedriver.storage.googleapis.com/index.html?path=2.24 /...unzip下载并在... webdriver.chrome中提供它的路径("通往chromedriver的路径")
我在这里解释一下:
from selenium import webdriver
driver = webdriver.Chrome("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")
Run Code Online (Sandbox Code Playgroud)
如果我运行上面的代码,这是错误:
C:\Python27\python.exe C:/Users/Gaurav.Gaurav-PC/PycharmProjects/Learning/StackOverflow/SeleniumQuestion/test123.py
Traceback (most recent call last):
File "C:/Users/Gaurav.Gaurav-PC/PycharmProjects/Learning/StackOverflow/SeleniumQuestion/test123.py", line 4, in <module>
driver = webdriver.Chrome("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")
File "C:\Python27\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
self.service.start()
File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 86, in start
self.assert_process_still_running()
File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 99, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service C:\Program Files (x86)\Google
\Chrome\Application\chrome.exe unexpectedly exited. Status code was: 0
Run Code Online (Sandbox Code Playgroud)
这与@Weiziyoung在原始问题中提到的相同.
正如我所提到的,解决方案需要提供chromedriver的路径来代替chrome浏览器
driver = webdriver.Chrome("E:\Jars\chromedriver.exe")
Run Code Online (Sandbox Code Playgroud)
它将解决问题
| 归档时间: |
|
| 查看次数: |
16645 次 |
| 最近记录: |