|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
写爬虫, 代码是这样的
while True:
try:
rep = requests.get(url, headers=header, timeout=timeout)
rep.encoding = 'utf-8'
return rep.text
except TimeoutError:
return
except Exception as e:
return
现在遇到异常, 请问各位怎么解决, 现在就想把这个异常跳过去, 不要终端程序执行就好了
Traceback (most recent call last):
File "C:\Users\hsy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\packages\urllib3\connection.py", line 141, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "C:\Users\hsy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\packages\urllib3\util\connection.py", line 83, in create_connection
raise err
File "C:\Users\hsy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\packages\urllib3\util\connection.py", line 73, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\hsy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Users\hsy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 345, in _make_request
self._validate_conn(conn)
File "C:\Users\hsy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 844, in _validate_conn
conn.connect()
File "C:\Users\hsy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\packages\urllib3\connection.py", line 284, in connect
conn = self._new_conn()
File "C:\Users\hsy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\packages\urllib3\connection.py", line 150, in _new_conn
self, "Failed to establish a new connection: %s" % e)
requests.packages.urllib3.exceptions.NewConnectionError: <requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x03AA3F10>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\hsy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\adapters.py", line 423, in send
timeout=timeout
File "C:\Users\hsy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 649, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Users\hsy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\packages\urllib3\util\retry.py", line 376, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.google.com.hk', port=443): Max retries exceeded with url: /search?num=100&newwindow=1&safe=strict&q=1192491-61-4&oq=1192491-61-4&gs_l=serp.12...0.0.0.68587.0.0.0.0.0.0.0.0..0.0....0...1c..64.serp..0.0.0.UcKsPMPWUts (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x03AA3F10>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。',))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/hsy/PycharmProjects/test/g-search.py", line 59, in <module>
k = getresult(keyword)
File "C:/Users/hsy/PycharmProjects/test/g-search.py", line 40, in getresult
res = requests.get(url, headers = header)
File "C:\Users\hsy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\api.py", line 70, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\hsy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\api.py", line 56, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\hsy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\sessions.py", line 488, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\hsy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\sessions.py", line 609, in send
r = adapter.send(request, **kwargs)
File "C:\Users\hsy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\adapters.py", line 487, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='www.google.com.hk', port=443): Max retries exceeded with url: /search?num=100&newwindow=1&safe=strict&q=1192491-61-4&oq=1192491-61-4&gs_l=serp.12...0.0.0.68587.0.0.0.0.0.0.0.0..0.0....0...1c..64.serp..0.0.0.UcKsPMPWUts (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x03AA3F10>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。',))
|
|