Python 在每个第二个循环中切换变量?

标签 python python-3.x

proxies1 = {'http': 'http://199.193.251.1:3128', 'https': 'http://199.193.251.1:3128'}
proxies2 = {'http': 'http://199.193.251.1:3128', 'https': 'http://199.193.251.1:3128'}
proxies3 = {'http': 'http://199.193.251.1:3128', 'https': 'http://199.193.251.1:3128'}
proxies4 = {'http': 'http://199.193.251.1:3128', 'https': 'http://199.193.251.1:3128'}
proxies5 = {'http': 'http://199.193.251.1:3128', 'https': 'http://199.193.251.1:3128'}
proxies6 = {'http': 'http://199.193.251.1:3128', 'https': 'http://199.193.251.1:3128'}
proxies7 = {'http': 'http://199.193.251.1:3128', 'https': 'http://199.193.251.1:3128'}
proxies8 = {'http': 'http://199.193.251.1:3128', 'https': 'http://199.193.251.1:3128'}
proxies9 = {'http': 'http://199.193.251.1:3128', 'https': 'http://199.193.251.1:3128'}
proxies10 = {'http': 'http://199.193.251.1:3128', 'https': 'http://199.193.251.1:3128'}


ProxyList = [proxies1,proxies2,proxies3,proxies4,proxies5,proxies6,proxies7,proxies8,proxies9,proxies10]

每次此循环循环两次时,我都会尝试切换代理...

for channel in ChannelList:
    ChannelURL = ("https://url.com/b/" + str(channel) + "/app/basic/a/plusone/buzz:" + videoID + "?cbp=ck8a3bhdyjck&sview=1&cid=5&soc-app=115&soc-platform=1&spath=/b/" + str(channel) +"/app/basic/stream/" + videoID)
    soup = BeautifulSoup(s.get(ChannelURL, PROXY VARIABLE GOES HERE).text, "html.parser")
    for inp in soup.select(".jlvUSc input[name]"):
        if inp["name"] not in form_data1:
            form_data1[inp["name"]] = inp["value"]
    s.post(ChannelURL, form_data1)

Python 3.4

我正在与 Python Request 合作

最佳答案

这将每两个循环切换代理:

for loop,channel in enumerate(ChannelList):
    proxies = ProxyList[loop // 2 % len(ProxyList)]

关于Python 在每个第二个循环中切换变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40196518/

相关文章:

python - 的影响?在正则表达式字符串中

python-2.7 - ImportError : No module named 'skimage' , 但我安装了所有依赖项和 scikit-image

python - matplotlib 中矩形数组的曲面图

python-3.x - 在另一列的指定组中查找另一列中存在重复项的行

python - 如何链接可能在 Python 中返回 None 的属性查找?

python 数据透视表 - 列是日期,应该正确排序

python - 如何在 Docker 容器中运行 Python Flask

python - 如何使用可调用作为 pytest parametrize() 参数?

python-3.x - Pandas append 返回带有 NaN 值的 DF

python-3.x - 如何用其他内容替换数据帧列的每个 "elements"的一部分