@[TOC](python 爬虫 ConnectionError: HTTPConnectionPool(host, port=80): Read timed out
python 爬虫 ConnectionError: HTTPConnectionPool(host, port=80): Read timed out
(1)爬取红楼梦全部章节过程中章节爬取不全
代码为
chaper_response=requests.get(url=chaper_url,headers=headers)
(2)根据搜索报错解决方案,建议设置timeout
因此,修改代码为
chaper_response=requests.get(url=chaper_url,headers=headers,timeout=5)
然鹅,依然是爬取到50章所有就返回Time read out
(3)最后,参考回答:https://www.jianshu.com/p/17c921639ad0
修改代码为
chaper_response=requests.get(url=chaper_url,headers=headers,timeout=(5,10))
设置了timeout()第二个参数,才是响应时长(一般报错:read time out);而第一个参数,是请求时长(一般报错:connection time out)
最后成功下载到全部章节!开心!!!!