【问题标题】:100,000 HTTP Response Code Checks100,000 次 HTTP 响应代码检查
【发布时间】:2015-05-04 08:39:58
【问题描述】:

我有一个大约 100,000 个链接的列表,我想检查其 HTTP 响应代码。以编程方式执行此检查的最佳方法可能是什么?

我正在考虑使用以下 Python 代码:

import requests
try:
  for x in range(0, 100000):
    r = requests.head(''.join(["http://stackoverflow.com/", str(x)]))
    # They'll actually be read from a file, and aren't sequential
    print r.status_code
except requests.ConnectionError:
  print "failed to connect"

.. 但我没有意识到一次检查如此大量的 URL 的潜在副作用。想法?

【问题讨论】:

  • 找到了here 对完全相同的问题的答案!

标签: python http-headers


【解决方案1】:

我能想到的唯一副作用是时间,您可以通过并行发出请求来减轻它。 (使用http://gevent.org/https://docs.python.org/2/library/thread.html)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-12
    • 2017-12-06
    • 1970-01-01
    相关资源
    最近更新 更多