|
新人刚入门爬虫,初步写一段代码。py3.5.1版本,运行疯狂报错,我很绝望啊,请问各种大哥大姐,这是怎么回事import requests
from bs4 import BeautifulSoup
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
'accept-encoding': 'gzip, deflate, sdch, br',
'accept-language': 'zh-CN,zh;q=0.8'
}
url = 'http://http://bbs.tianya.cn/'
r = requests.get(url, headers=headers).content
soup=BeautifulSoup.findAll('div',{"class":"title"})
报错信息如下
Traceback (most recent call last):
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\packages\urllib3\connection.py", line 141, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\packages\urllib3\util\connection.py", line 60, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\lib\socket.py", line 732, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11004] getaddrinfo failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 356, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 1083, in request
self._send_request(method, url, body, headers)
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 1128, in _send_request
self.endheaders(body)
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 1079, in endheaders
self._send_output(message_body)
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 911, in _send_output
self.send(msg)
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 854, in send
self.connect()
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\packages\urllib3\connection.py", line 166, in connect
conn = self._new_conn()
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\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.HTTPConnection object at 0x0000000002FFBB38>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\adapters.py", line 423, in send
timeout=timeout
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 649, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\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: HTTPConnectionPool(host='http', port=80): Max retries exceeded with url: //bbs.tianya.cn/ (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x0000000002FFBB38>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed',))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/cong/11.py", line 11, in <module>
r =requests.get(rul, headers=headers).content
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\api.py", line 70, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\api.py", line 56, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\sessions.py", line 488, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\sessions.py", line 609, in send
r = adapter.send(request, **kwargs)
File "C:\Users\cong\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\adapters.py", line 487, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='http', port=80): Max retries exceeded with url: //bbs.tianya.cn/ (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x0000000002FFBB38>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed',))
好长,这到底是怎么回事。新人求问,有什么不对的请见谅
|
|