Python网络爬虫urllib.error.URLError : <urlopen error Temporary failure in name resolution>

标签 python web-crawler urllib

我正在从网络上抓取一些数据,由于我应该获取的数据很大,我同时收到了 500 多个请求(通过 urllib.request.urlopen(url)通过 multiprocessing 进行池化。

这里的问题是抛出如下错误:

urllib.error.URLError: urlopen error Temporary failure in name resolution

经过一番研究,我发现这个问题是由于请求过多时无法关闭连接造成的。但是还没有找到解决这个问题的办法。

我应该将同时连接限制在某个安全范围内,还是更改urllib 请求配置?

开发环境:

  • Ubuntu 16.04
  • python 3.6

最佳答案

尝试使用 Session Objects来自请求库。 如文档中所述,

The Session object allows you to persist certain parameters across requests. It also persists cookies across all requests made from the Session instance, and will use urllib3's connection pooling. So if you're making several requests to the same host, the underlying TCP connection will be reused, which can result in a significant performance increase (see HTTP persistent connection).

也许这个其他thread关于高效网络抓取的信息可以帮助您。

关于Python网络爬虫urllib.error.URLError : <urlopen error Temporary failure in name resolution>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49718857/

相关文章:

python - 查看 Tkinter 小部件是否存在(不使用 .winfo_exists)

python - Tweepy 截断状态

c++ - 在 C++ 中,我在使用队列和 libcurl 时遇到错误

java - 我应该使用哪个用户代理?

http-headers - HTTP 基本身份验证不适用于 Python 3

python - Tensorflow:导入预训练模型(mobilenet、.pb、.ckpt)

java - 爬虫引擎架构——Java/Perl整合

Python2 与 Python3 post 请求

Python 3.5 urllib 无法在浏览器中打开网页

python - 在 Python 中缩放和移动 Scipy 分布