【问题标题】:Python: how to use lots of proxies in module REQUESTSPython:如何在模块 REQUESTS 中使用大量代理
【发布时间】:2016-10-20 10:29:21
【问题描述】:

我对模块requests 有一些困难。 它需要参数proxies。 我在这个模块的this question 描述中看到,我明白,它只需要一个来自字典的代理。 但是,如果一个代理被阻止? 我想使用带有很多代理的字典,如果一个代理被阻止,我想使用另一个代理,但是我该怎么做呢?

【问题讨论】:

  • 您将很快用完代理,您可能会发现在 PhantomJs 中使用 selenium 是一个更好的选择

标签: python proxy python-requests


【解决方案1】:

定义list_of_proxies = [{proxy_0}, {proxy_1}, ...],然后根据您的代码逻辑将r = requests.get(url, headers=headers, proxies = list_of_proxies[i]) 粘贴到您设置i 的位置。

【讨论】:

  • 感谢您的回答。我会尽快尝试
【解决方案2】:

定义list of proxies,然后使用random.choice(list) 函数从列表中调用随机选择并在您的代码中使用。

谢谢。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-09
    • 2021-09-07
    • 1970-01-01
    • 1970-01-01
    • 2014-11-05
    • 1970-01-01
    • 2016-07-22
    相关资源
    最近更新 更多