失败后如何使用检查站点重复代理服务器

问题描述 投票:0回答:1

我的代码在失败后不会重复

import requests

with open("valid_proxies.txt", "r") as f:
    proxies = f.read().split("\n")


sites_to_check = ["https://open.spotify.com/"]



counter = 1

for site in sites_to_check:
    try:
        print(f"Using the proxy: {proxies[counter]}")
        res = requests.get(site, proxies={"http": proxies[counter],
                                        "https": proxies[counter]})
        print(res.status_code)
        print(res.text)
    except:
        print("Failed")
    finally:
        counter += 10
python proxy http-status-codes
1个回答
0
投票

您需要另一个循环来使用另一个代理尝试同一站点。

for site in sites_to_check:
    for proxy  in proxies[1::10]:
        try:
            print(f"Connecting to {site} using proxy {proxy}")
            res = requests.get(site, proxies={"http": proxy, "https": proxy})
            print(res.status_code, res.text, sep="\n")
        except:
            print("failed")
© www.soinside.com 2019 - 2024. All rights reserved.