我试图爬行https://foodtracer.taipei.gov.tw/Front/Chain/Product?id=12411160带有
> import requests
> `url = 'https://foodtracer.taipei.gov.tw/Front/Chain/Product?id=12411160'
>
> r = requests.post(url)
>
> print(r.status_code) # 200
>
> if r.status_code == requests.codes.ok: # OK! print("OK!")`
但这发生了:
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1124)
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='foodtracer.taipei.gov.tw', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1124)')))
requests.exceptions.SSLError: HTTPSConnectionPool(host='foodtracer.taipei.gov.tw', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1124)')))
我尝试了/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8 -m pip install --upgrade pip
,但错误仍然出现
我还有其他方法可以爬网此网站吗?
您需要在请求中添加verify=False
:
r = requests.post(url, verify=False)
这将产生一个警告,尽管你可以选择抑制它