我正在尝试从网站上抓取文本,并且我正在使用请求模块来执行此操作。
使用给定的代码(此处以 Facebook 为例)
requests.get('http://facebook.com')
我收到以下错误:
SSLError: HTTPSConnectionPool(host='facebook.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))
我尝试了以下方法,但没有成功:
pip install certifi
pip install certifi_win32
任何帮助将不胜感激!谢谢!
你可以试试这个方法
import requests
from urllib3.exceptions import InsecureRequestWarning
from urllib3 import disable_warnings
disable_warnings(InsecureRequestWarning)
page = requests.get('http://facebook.com', verify=False)
print(page.content)
问题可能源于过于激进的安全措施,您可以通过两个步骤修复:
我在抓取网站时遇到了同样的问题。我尝试设置 False 来验证并使用 CA 证书,两者都不起作用。阅读文档我发现Session Objects
我向同一主机发出了多个请求,因此我收到“URL 超出最大重试次数”
针对您的情况,您可以尝试以下方法:
s = requests.Session()
response = s.get('http://facebook.com')
我也遇到了同样的问题,但差别很小。
我试图通过IP访问该网站
requests.get('http://10.20.30.40', verify=False)
所有提供的解决方案都失败了,直到我使用域名而不是IP。