如何在循环发送请求时使用代理列表中的所有代理?
How to use all proxies from proxy list while sending requests in cycle?
我只是想使用我所有的代理来发送请求,但只使用了一个代理。
this is my code:
import requests
import random
import string
import random
from proxy_requests import ProxyRequests
proxies = {'https': 'https://104.148.46.2:3121',
'https': 'https://134.19.254.2:21231',
'https': 'https://45.76.222.196:8118',
'https': 'https://103.87.207.188:59064',
'https': 'https://182.74.40.146:30909',
'https': 'https://5.196.132.115:3128',
'https': 'https://200.142.120.90:56579',
'https': 'https://24.172.82.94:53281',
'https': 'https://213.141.93.60:32125',
'https': 'https://167.71.6.78:3128',
'https': 'https://202.166.205.78:58431',
'https': 'https://37.82.13.84:8080',
'https': 'https://132.255.23.157:3128'}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36
OPR/63.0.3368.71'}
while True:
with requests.Session() as s:
register_data = {"POST":"CENSORED"}
url = 'CENSORED'
r = s.post(url, json=register_data, proxies = proxies)
print(r.content)
print (proxies)
输出是:
b'"CENSORED"'
{'https': 'https://132.255.23.157:3128'}
b'"CENSORED"'
{'https': 'https://132.255.23.157:3128'}
b'"CENSORED"'
{'https': 'https://132.255.23.157:3128'}
我需要这样的输出:
b'"CENSORED"'
{'https': 'https://202.166.205.78:58431'}
b'"CENSORED"'
{'https': 'https://103.87.207.188:59064'}
b'"CENSORED"'
{'https': 'https://132.255.23.157:3128'}
我尝试使用代理请求模块(proxy_requests),但我需要使用自定义代理。
您正在创建代理字典,这是错误的。 'https'
是一个密钥,并且只有一个名称为 https 的密钥。您最后将值 'https://132.255.23.157:3128'
分配给 'https'
,因此每次打印 proxies
时,您都会得到 {'https': 'https://132.255.23.157:3128'}
您必须为 proxies
创建字典列表才能获得所需的输出。
import requests
import random
proxies = [{'https': 'https://104.148.46.2:3121'}, {'https': 'https://134.19.254.2:21231'}, {'https': 'https://45.76.222.196:8118'}, {'https': 'https://103.87.207.188:59064'}, {'https': 'https://182.74.40.146:30909'}, {'https': 'https://5.196.132.115:3128'}, {'https': 'https://200.142.120.90:56579'}, {'https': 'https://24.172.82.94:53281'}, {'https': 'https://213.141.93.60:32125'}, {'https': 'https://167.71.6.78:3128'}, {'https': 'https://202.166.205.78:58431'}, {'https': 'https://37.82.13.84:8080'}, {'https': 'https://132.255.23.157:3128'}]
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36OPR/63.0.3368.71'}
while True:
with requests.Session() as s:
register_data = {"POST":"CENSORED"}
url = 'CENSORED'
r = s.post(url, json=register_data, proxies = random.choice(proxies))
print(r.content)
print (proxies)
我只是想使用我所有的代理来发送请求,但只使用了一个代理。
this is my code:
import requests
import random
import string
import random
from proxy_requests import ProxyRequests
proxies = {'https': 'https://104.148.46.2:3121',
'https': 'https://134.19.254.2:21231',
'https': 'https://45.76.222.196:8118',
'https': 'https://103.87.207.188:59064',
'https': 'https://182.74.40.146:30909',
'https': 'https://5.196.132.115:3128',
'https': 'https://200.142.120.90:56579',
'https': 'https://24.172.82.94:53281',
'https': 'https://213.141.93.60:32125',
'https': 'https://167.71.6.78:3128',
'https': 'https://202.166.205.78:58431',
'https': 'https://37.82.13.84:8080',
'https': 'https://132.255.23.157:3128'}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36
OPR/63.0.3368.71'}
while True:
with requests.Session() as s:
register_data = {"POST":"CENSORED"}
url = 'CENSORED'
r = s.post(url, json=register_data, proxies = proxies)
print(r.content)
print (proxies)
输出是:
b'"CENSORED"'
{'https': 'https://132.255.23.157:3128'}
b'"CENSORED"'
{'https': 'https://132.255.23.157:3128'}
b'"CENSORED"'
{'https': 'https://132.255.23.157:3128'}
我需要这样的输出:
b'"CENSORED"'
{'https': 'https://202.166.205.78:58431'}
b'"CENSORED"'
{'https': 'https://103.87.207.188:59064'}
b'"CENSORED"'
{'https': 'https://132.255.23.157:3128'}
我尝试使用代理请求模块(proxy_requests),但我需要使用自定义代理。
您正在创建代理字典,这是错误的。 'https'
是一个密钥,并且只有一个名称为 https 的密钥。您最后将值 'https://132.255.23.157:3128'
分配给 'https'
,因此每次打印 proxies
时,您都会得到 {'https': 'https://132.255.23.157:3128'}
您必须为 proxies
创建字典列表才能获得所需的输出。
import requests
import random
proxies = [{'https': 'https://104.148.46.2:3121'}, {'https': 'https://134.19.254.2:21231'}, {'https': 'https://45.76.222.196:8118'}, {'https': 'https://103.87.207.188:59064'}, {'https': 'https://182.74.40.146:30909'}, {'https': 'https://5.196.132.115:3128'}, {'https': 'https://200.142.120.90:56579'}, {'https': 'https://24.172.82.94:53281'}, {'https': 'https://213.141.93.60:32125'}, {'https': 'https://167.71.6.78:3128'}, {'https': 'https://202.166.205.78:58431'}, {'https': 'https://37.82.13.84:8080'}, {'https': 'https://132.255.23.157:3128'}]
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36OPR/63.0.3368.71'}
while True:
with requests.Session() as s:
register_data = {"POST":"CENSORED"}
url = 'CENSORED'
r = s.post(url, json=register_data, proxies = random.choice(proxies))
print(r.content)
print (proxies)