import requests
import json
# API credentials
API_PUBLIC_KEY = "your_public_key"
API_PRIVATE_KEY = "your_private_key"
BASE_URL = "https://api.pingproxies.com/1.0/public"
# Headers for authentication
headers = {
"X-API-Public-Key": API_PUBLIC_KEY,
"X-API-Private-Key": API_PRIVATE_KEY,
"Content-Type": "application/json"
}
# For this example, we'll directly use US static residential proxies
product_code = "isp_us" # Change this to your desired product code
quantity = 5 # Change this to your desired quantity
# Step 2: Create a checkout
checkout_url = f"{BASE_URL}/user/checkout/create"
checkout_payload = {
"product_code": product_code,
"quantity": quantity,
"cycle_interval": "month",
"cycle_interval_count": 1
}
checkout_response = requests.post(checkout_url, headers=headers, json=checkout_payload)
if checkout_response.status_code != 201:
print(f"Error creating checkout: {checkout_response.status_code}")
print(checkout_response.text)
exit(1)
checkout_data = checkout_response.json()
print(f"Checkout created successfully!")
# Extract service ID directly from the response
service_id = checkout_data["data"]["service_id"]
print(f"Service ID: {service_id}")
# In a production environment, you might want to add a polling mechanism
# to check if the service is active before proceeding
# time.sleep(10) # Simple wait - replace with polling in production
# Step 3: Export proxies to a text file using list_by_search
export_url = f"{BASE_URL}/user/proxy/list_by_search"
export_params = {
"service_id": service_id,
"list_format": "http", # Format: http, socks5, socks5h, or standard
"list_protocol": "http", # Protocol: http or socks5
"list_authentication": "username_and_password" # Authentication type
}
export_response = requests.get(export_url, headers=headers, params=export_params)
if export_response.status_code != 200:
print(f"Error exporting proxies: {export_response.status_code}")
print(export_response.text)
exit(1)
export_data = export_response.json()
proxies = export_data["data"]
# Write proxies to a text file
filename = f"{product_code}_proxies.txt"
with open(filename, "w") as f:
for proxy in proxies:
f.write(f"{proxy}\n")
print(f"Successfully exported {len(proxies)} proxies to {filename}")