我的代码在失败后不会重复
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
您需要另一个循环来使用另一个代理尝试同一站点。
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")