我正在研究一些特定网站的网络抓取,因此我使用 python 3 requests 包和 beautifulsoup。在对某些网站进行测试时,我收到此错误:
requests.exceptions.SSLError: HTTPSConnectionPool(host='autoglassbodyrepair.lawshield.co.uk', port=443): 超过 url 的最大重试次数: / (由 SSLError(SSLError("握手错误: Error([('SSL 例程) ', 'tls_process_server_certificate', '证书验证失败')],)",),))
import requests as rq
import bs4
current_url = 'autoglassbodyrepair.lawshield.co.uk'
try:
req = rq.get(current_url)
except rq.exceptions.RequestException as e:
print(e)
else:
soup = bs4.BeautifulSoup(r.content, "html.parser")
text = soup.findAll(text = True)
Run Code Online (Sandbox Code Playgroud)
当我尝试浏览器时,它显示证书已过期,但我可以处理 https 被禁止并变成红色的页面。我想要的是,如果出现不允许我访问该页面的异常,我会忽略它并进入下一页进行处理,但如果没有异常,我会处理当前页面并忽略那些 SSl 证书。
在此先感谢您的帮助 !