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.")
Tập lệnh này xác định danh sách proxy và cung cấp các hàm để xoay vòng chúng cho mỗi yêu cầu. Bạn có thể điều chỉnh danh sách proxy và URL mục tiêu theo yêu cầu của mình. Đảm bảo thay thế 'http://example.com'
với URL bạn muốn gửi yêu cầu tới.
Bình luận (0)
Chưa có bình luận nào ở đây, bạn có thể là người đầu tiên!