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.")
Bu komut dosyası bir proxy listesi tanımlar ve her istek için bunlar arasında geçiş yapacak işlevler sağlar. Proxy listesini ve hedef URL'yi gereksinimlerinize göre ayarlayabilirsiniz. Değiştirdiğinizden emin olun 'http://example.com'
istekleri göndermek istediğiniz URL ile.
Yorumlar (0)
Burada henüz yorum yok, ilk siz olabilirsiniz!