import requests
# List of proxies
proxy_list = [
'proxy1.example.com:8000',
'proxy2.example.com:8000',
'proxy3.example.com:8000',
# Add more proxies as needed
]
# Function to rotate proxies
def get_proxy():
global proxy_list
proxy = proxy_list.pop(0)
proxy_list.append(proxy)
return {'http': 'http://' + proxy, 'https': 'https://' + proxy}
# Function to make a request using rotated proxy
def make_request(url):
try:
proxy = get_proxy()
response = requests.get(url, proxies=proxy)
if response.status_code == 200:
return response.text
else:
print(f"Request failed with status code: {response.status_code}")
return None
except Exception as e:
print(f"An error occurred: {str(e)}")
return None
# Example usage
if __name__ == "__main__":
target_url = 'http://example.com'
for _ in range(10): # Make 10 requests
response = make_request(target_url)
if response:
print(response)
else:
print("Request failed.")
Skrip ini mentakrifkan senarai proksi dan menyediakan fungsi untuk berputar melaluinya untuk setiap permintaan. Anda boleh melaraskan senarai proksi dan URL sasaran mengikut keperluan anda. Pastikan untuk menggantikan 'http://example.com'
dengan URL yang anda ingin hantar permintaan.
Komen (0)
Tiada ulasan di sini lagi, anda boleh menjadi yang pertama!