python+selenium启动浏览器报错
代码:#-*-coding:utf-8-*-
from selenium import webdriver
from time import sleep
driver = webdriver.Chrome()
driver.get('https://www.baidu.com')
driver.find_element_by_name('wd').send_keys('selenium')
driver.find_element_by_id('su').click()
sleep(3)
driver.close()
谷歌浏览器版本:最新的62驱动是V2.33
运行脚本后报错:D:\Python\Python36\python.exe D:/PyCharm/webtest.pyTraceback (most recent call last):File "D:\Python\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 67, in __init__ desired_capabilities=desired_capabilities)File "D:\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 87, in __init__ self.start_session(desired_capabilities, browser_profile)File "D:\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 141, in start_session 'desiredCapabilities': desired_capabilities,File "D:\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 199, in execute response = self.command_executor.execute(driver_command, params)File "D:\Python\Python36\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 395, in execute return self._request(command_info, url, body=data)File "D:\Python\Python36\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 426, in _request resp = self._conn.getresponse()File "D:\Python\Python36\lib\http\client.py", line 1331, in getresponse response.begin()File "D:\Python\Python36\lib\http\client.py", line 297, in begin version, status, reason = self._read_status()File "D:\Python\Python36\lib\http\client.py", line 258, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")File "D:\Python\Python36\lib\socket.py", line 586, in readinto return self._sock.recv_into(b)ConnectionResetError: 远程主机强迫关闭了一个现有的连接。During handling of the above exception, another exception occurred:Traceback (most recent call last):File "D:\Python\Python36\lib\urllib\request.py", line 1318, in do_open encode_chunked=req.has_header('Transfer-encoding'))File "D:\Python\Python36\lib\http\client.py", line 1239, in request self._send_request(method, url, body, headers, encode_chunked)File "D:\Python\Python36\lib\http\client.py", line 1285, in _send_request self.endheaders(body, encode_chunked=encode_chunked)File "D:\Python\Python36\lib\http\client.py", line 1234, in endheaders self._send_output(message_body, encode_chunked=encode_chunked)File "D:\Python\Python36\lib\http\client.py", line 1026, in _send_output self.send(msg)File "D:\Python\Python36\lib\http\client.py", line 964, in send self.connect()File "D:\Python\Python36\lib\http\client.py", line 936, in connect (self.host,self.port), self.timeout, self.source_address)File "D:\Python\Python36\lib\socket.py", line 722, in create_connection raise errFile "D:\Python\Python36\lib\socket.py", line 713, in create_connection sock.connect(sa)ConnectionRefusedError: 由于目标计算机积极拒绝,无法连接。During handling of the above exception, another exception occurred:Traceback (most recent call last):File "D:/PyCharm/webtest.py", line 5, in <module> driver = webdriver.Chrome()File "D:\Python\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__ self.quit()File "D:\Python\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 88, in quit self.service.stop()File "D:\Python\Python36\lib\site-packages\selenium\webdriver\chrome\service.py", line 111, in stop url_request.urlopen("http://127.0.0.1:%d/shutdown" % self.port)File "D:\Python\Python36\lib\urllib\request.py", line 223, in urlopen return opener.open(url, data, timeout)File "D:\Python\Python36\lib\urllib\request.py", line 526, in open response = self._open(req, data)File "D:\Python\Python36\lib\urllib\request.py", line 544, in _open '_open', req)File "D:\Python\Python36\lib\urllib\request.py", line 504, in _call_chain result = func(*args)File "D:\Python\Python36\lib\urllib\request.py", line 1346, in http_open return self.do_open(http.client.HTTPConnection, req)File "D:\Python\Python36\lib\urllib\request.py", line 1320, in do_open raise URLError(err)urllib.error.URLError: <urlopen error 由于目标计算机积极拒绝,无法连接。>Process finished with exit code 1
百度搜索框变成wd了? 1、你把https://www.baidu.com换成http://www.baidu.com试试
2、你是不是没有下载谷歌浏览器的驱动,这是谷歌浏览器的版本和驱动版本对应,http://blog.csdn.net/huilan_same/article/details/51896672;这是驱动的下载地址http://npm.taobao.org/mirrors/chromedriver/,下载完驱动后把驱动放在Chrome\Application\下面,并配置环境变量,再试试 Real_小T 发表于 2017-11-18 23:10
百度搜索框变成wd了?
原来也是wd呀 是不是驱动器 或是 浏览器版本不对 梦想家 发表于 2017-11-21 09:33
原来也是wd呀
一直都是kw好么 Real_小T 发表于 2017-11-21 09:40
一直都是kw好么
你那是ID,这个是name。id是kw,name是wd 梦想家 发表于 2017-11-21 09:47
你那是ID,这个是name。id是kw,name是wd
soga 我刚发现{:4_90:} Real_小T 发表于 2017-11-21 09:57
soga 我刚发现
哈哈我之前猜你就是一直用id还真是 浏览器版本与驱动不正确
页:
[1]