|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
求助下各位大佬,下面的这个问题怎么解决,貌似是不让我用代理ip
import requests
import bs4
url = r"https://search.sciencemag.org/?searchTerm=psychology&order=newest&limit=textFields&pageSize=10&startDate=2015-01-01&endDate=2021-09-08&articleTypes=Research%20and%20reviews&source=sciencemag%7CScience"
header = {"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"}
response = requests.get(url, headers = header)
soup = bs4.BeautifulSoup(response.text, "html.parser")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_62048/3130801728.py in <module>
4 url = r"https://search.sciencemag.org/?searchTerm=psychology&order=newest&limit=textFields&pageSize=10&startDate=2015-01-01&endDate=2021-09-08&articleTypes=Research%20and%20reviews&source=sciencemag%7CScience"
5 header = {"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"}
----> 6 response = requests.get(url, headers = header)
7 soup = bs4.BeautifulSoup(response.text, "html.parser")
8 soup
C:\ProgramData\Anaconda3\lib\site-packages\requests\api.py in get(url, params, **kwargs)
74
75 kwargs.setdefault('allow_redirects', True)
---> 76 return request('get', url, params=params, **kwargs)
77
78
C:\ProgramData\Anaconda3\lib\site-packages\requests\api.py in request(method, url, **kwargs)
59 # cases, and look like a memory leak in others.
60 with sessions.Session() as session:
---> 61 return session.request(method=method, url=url, **kwargs)
62
63
C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
540 }
541 send_kwargs.update(settings)
--> 542 resp = self.send(prep, **send_kwargs)
543
544 return resp
C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py in send(self, request, **kwargs)
653
654 # Send the request
--> 655 r = adapter.send(request, **kwargs)
656
657 # Total elapsed time of the request (approximately)
C:\ProgramData\Anaconda3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
437 try:
438 if not chunked:
--> 439 resp = conn.urlopen(
440 method=request.method,
441 url=url,
C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
694 )
695 if is_new_proxy_conn and http_tunnel_required:
--> 696 self._prepare_proxy(conn)
697
698 # Make the request on the httplib connection object.
C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py in _prepare_proxy(self, conn)
962 conn.tls_in_tls_required = True
963
--> 964 conn.connect()
965
966 def _new_conn(self):
C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connection.py in connect(self)
357 if self._is_using_tunnel():
358 if self.tls_in_tls_required:
--> 359 conn = self._connect_tls_proxy(hostname, conn)
360 tls_in_tls = True
361
C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connection.py in _connect_tls_proxy(self, hostname, conn)
498 # If no cert was provided, use only the default options for server
499 # certificate validation
--> 500 return ssl_wrap_socket(
501 sock=conn,
502 ca_certs=self.ca_certs,
C:\ProgramData\Anaconda3\lib\site-packages\urllib3\util\ssl_.py in ssl_wrap_socket(sock, keyfile, certfile, cert_reqs, ca_certs, server_hostname, ssl_version, ciphers, ssl_context, ca_cert_dir, key_password, ca_cert_data, tls_in_tls)
451 )
452 else:
--> 453 ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
454 return ssl_sock
455
C:\ProgramData\Anaconda3\lib\site-packages\urllib3\util\ssl_.py in _ssl_wrap_socket_impl(sock, ssl_context, tls_in_tls, server_hostname)
493 return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
494 else:
--> 495 return ssl_context.wrap_socket(sock)
C:\ProgramData\Anaconda3\lib\ssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session)
498 # SSLSocket class handles server_hostname encoding before it calls
499 # ctx._wrap_socket()
--> 500 return self.sslsocket_class._create(
501 sock=sock,
502 server_side=server_side,
C:\ProgramData\Anaconda3\lib\ssl.py in _create(cls, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, context, session)
995 "client mode")
996 if context.check_hostname and not server_hostname:
--> 997 raise ValueError("check_hostname requires server_hostname")
998
999 kwargs = dict(
ValueError: check_hostname requires server_hostname |
|