首页 > 解决方案 > 迭代两个不同大小的列表

问题描述

import itertools
Value = ['178.217.107.8:53281', '91.90.191.238:8080', '27.116.51.114:8080']
content = ['link1','link2','link3']

for a,b in zip(Value , itertools.cycle(content)):
   print(a,b)

我正在寻找的是,如果在第一个列表(代理列表)中假设任何代理不起作用然后传递并移动到列表中的下一个,并行内容列表中当前阶段的元素应该保持不变。

例如:对于第一个元素,输出为:178.217.107.8:53281 Link1

但是如果 178.217.107.8:53281 抛出错误,则将循环中的“a”值作为并将输出作为 91.90.191.238:8080 Link1

标签: python-3.xselenium-webdriverweb-scrapingproxy

解决方案


伪代码如下:

list_of_proxies = ['178.217.107.8:53281', '91.90.191.238:8080', '27.116.51.114:8080']
list_of_links = ['link1','link2','link3']
for proxy in list_of_proxies:
    for link in list_of_links:
        # call some method to check if the proxy worked and store in a variable
        success = method_call(proxy, link) # assuming return type as boolean
        if !success:
            break
        else:
            # remove the successful link from the list, depending on your exact requirement
            list_of_links.remove(link)

推荐阅读