报错
![TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败](https://gaozhiyuan.net/wp-content/uploads/2021/06/2021-06-19-18-43-39.png)
未添加 timeout 参数,爬取到第180多行就会出现错误:
![TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败](https://gaozhiyuan.net/wp-content/uploads/2021/06/2021-06-19-18-44-40.png)
解决方案
在遇到 爬虫 TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败 这个问题的时候,只需要在requests.get函数中新增一个timeout参数即可:
res = requests.get(url, headers=headers, timeout=(3, 7))
现在一切正常:
![TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败](https://gaozhiyuan.net/wp-content/uploads/2021/06/2021-06-19-18-51-56.png)
参考文献:https://blog.csdn.net/qq_39451578/article/details/104216121