Exporting a list of proxies from a particular service
Learn how to export a formatted list of proxies from a specific service using the list_by_search endpoint
This example demonstrates how to export a formatted list of proxies from a specific service using the list_by_search endpoint with filtering parameters. Unlike the basic search, this endpoint returns ready-to-use proxy strings in your desired format.
import requestsimport osfrom datetime import datetime# API credentialsAPI_PUBLIC_KEY ="your_public_key"API_PRIVATE_KEY ="your_private_key"BASE_URL ="https://api.pingproxies.com/1.0/public"# Headers for authenticationheaders ={"X-API-Public-Key": API_PUBLIC_KEY,"X-API-Private-Key": API_PRIVATE_KEY}defexport_service_proxies(service_id):""" Export a formatted list of proxies from a specific service. Note: You can modify format_type and protocol parameters to get different formats:- format_type options:"standard","http","socks5","socks5h"- protocol options:"http"or"socks5" Args: service_id: ID of the service to export proxies from Returns: List of formatted proxy strings"""# Set up the parameters for list_by_search params ={"service_id": service_id,"list_format":"standard",# You can change this to "http", "socks5", or "socks5h""list_protocol":"http",# You can change this to "socks5""list_version":"ipv4",# IP version"list_authentication":"username_and_password"# Authentication type}# Make request to the list_by_search endpoint response = requests.get(f"{BASE_URL}/user/proxy/list_by_search", params=params, headers=headers)if response.status_code !=200:print(f"Error: {response.status_code}")print(response.text)return[] data = response.json()# The list endpoint returns the formatted proxies directly in data proxy_list = data["data"]print(f"Successfully retrieved {len(proxy_list)} formatted proxies from service {service_id}")return proxy_listdefexport_to_file(proxy_list, service_id):"""Export proxy list to a file."""# Create a default filename with timestamp timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") filename =f"service_{service_id}_proxies_{timestamp}.txt"# Write the proxy list to a filewithopen(filename,"w")asfile:for proxy in proxy_list:file.write(f"{proxy}\n")print(f"Exported {len(proxy_list)} proxies to {filename}")return filename# Example usageif __name__ =="__main__":# Replace with your actual service ID SERVICE_ID ="API-1234-5678"# Get proxies proxy_list = export_service_proxies(SERVICE_ID)# Export to fileif proxy_list: export_to_file(proxy_list, SERVICE_ID)# Print sample outputif proxy_list:print(f"\nSample output: {proxy_list[0]}")