# -*- coding:utf-8 -*-
import requests
r = requests.get("https://www.baidu.com")
print(r.cookies)
for key, value in r.cookies.items():
print(key + '=' + value)
问题如下
Traceback (most recent call last):
File "D:/pycharm/爬虫代码/requests_highusing/require_cookies.py", line 5, in <module>
r = requests.get("https://www.baidu.com")
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\requests\api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\requests\api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\requests\sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\requests\sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\requests\adapters.py", line 440, in send
timeout=timeout
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
chunked=chunked)
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 357, in _make_request
conn.request(method, url, **httplib_request_kw)
File "D:\pycharm\Anaconda3\Anaconda3\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "D:\pycharm\Anaconda3\Anaconda3\lib\http\client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "D:\pycharm\Anaconda3\Anaconda3\lib\http\client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "D:\pycharm\Anaconda3\Anaconda3\lib\http\client.py", line 1026, in _send_output
self.send(msg)
File "D:\pycharm\Anaconda3\Anaconda3\lib\http\client.py", line 986, in send
self.sock.sendall(data)
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 316, in sendall
sent = self._send_until_done(data[total_sent:total_sent + SSL_WRITE_BLOCKSIZE])
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 304, in _send_until_done
return self.connection.send(data)
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\OpenSSL\SSL.py", line 1644, in send
with _from_buffer(buf) as data:
AttributeError: __enter__
# -*- coding:utf-8 -*-
import requests
r = requests.get('https://github.com/favicon.ico')
print(r.text)
print(r.content)
出现的问题与上面相同
Traceback (most recent call last):
File "D:/pycharm/爬虫代码/requests/binary.py", line 4, in <module>
r = requests.get('https://github.com/favicon.ico')
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\requests\api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\requests\api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\requests\sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\requests\sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\requests\adapters.py", line 440, in send
timeout=timeout
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
chunked=chunked)
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 357, in _make_request
conn.request(method, url, **httplib_request_kw)
File "D:\pycharm\Anaconda3\Anaconda3\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "D:\pycharm\Anaconda3\Anaconda3\lib\http\client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "D:\pycharm\Anaconda3\Anaconda3\lib\http\client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "D:\pycharm\Anaconda3\Anaconda3\lib\http\client.py", line 1026, in _send_output
self.send(msg)
File "D:\pycharm\Anaconda3\Anaconda3\lib\http\client.py", line 986, in send
self.sock.sendall(data)
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 316, in sendall
sent = self._send_until_done(data[total_sent:total_sent + SSL_WRITE_BLOCKSIZE])
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 304, in _send_until_done
return self.connection.send(data)
File "D:\pycharm\Anaconda3\Anaconda3\lib\site-packages\OpenSSL\SSL.py", line 1644, in send
with _from_buffer(buf) as data:
AttributeError: __enter__
Process finished with exit code 1