抓取某小說(shuō)網(wǎng)站時(shí),因其https际乘,請(qǐng)求內(nèi)容時(shí)要驗(yàn)證證書(shū),獲取內(nèi)容失敗漂佩,報(bào)錯(cuò)如下:
Traceback (most recent call last):
File "C:/Users/cxqy003/PycharmProjects/untitled1/books.py", line 149, in <module>
book_detail()
File "C:/Users/cxqy003/PycharmProjects/untitled1/books.py", line 127, in book_detail
req = requests.get(url).text
File "C:\Users\cxqy003\Anaconda2\lib\site-packages\requests\api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\cxqy003\Anaconda2\lib\site-packages\requests\api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\cxqy003\Anaconda2\lib\site-packages\requests\sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\cxqy003\Anaconda2\lib\site-packages\requests\sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "C:\Users\cxqy003\Anaconda2\lib\site-packages\requests\adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.dingdiann.com', port=443)
這種問(wèn)題解決辦法就是搞定證書(shū)脖含,方法有許多,我選擇的是簡(jiǎn)單粗暴的不驗(yàn)證投蝉。
req = requests.get(url, verify=False).text
在請(qǐng)求時(shí)加入“verify=False”养葵,便可以不驗(yàn)證證書(shū),拿到內(nèi)容了瘩缆。