### Install Free-proxy Source: https://github.com/jundymek/free-proxy/blob/master/README.md Command to install the library via pip. ```bash pip install free-proxy ``` -------------------------------- ### Combine Proxy Parameters Source: https://github.com/jundymek/free-proxy/blob/master/README.md Example of using multiple parameters simultaneously. ```python proxy = FreeProxy(country_id=['US', 'BR'], timeout=0.3, rand=True).get() ``` -------------------------------- ### Proxy Return Format Source: https://github.com/jundymek/free-proxy/blob/master/README.md Example of the string format returned by the proxy getter. ```python 'http://113.160.218.14:8888' ``` -------------------------------- ### Get Default Proxy Source: https://github.com/jundymek/free-proxy/blob/master/README.md Fetches the first working proxy from default sources. ```python proxy = FreeProxy().get() ``` -------------------------------- ### Get Proxy with Combined Parameters Source: https://context7.com/jundymek/free-proxy/llms.txt Fetch a proxy server by combining multiple filtering criteria such as country, timeout, randomization, and protocol support. Ensure to handle potential FreeProxyException if no suitable proxy is found. ```python from fp.fp import FreeProxy from fp.errors import FreeProxyException # Complex filtering with multiple criteria try: proxy = FreeProxy( country_id=['US', 'BR'], timeout=0.3, rand=True, elite=True, https=True ).get() print(f"Found proxy: {proxy}") except FreeProxyException as e: print(f"No proxy found: {e.message}") ``` -------------------------------- ### Selenium Integration with Proxies Source: https://context7.com/jundymek/free-proxy/llms.txt Integrate Free Proxy with Selenium WebDriver to mask your IP address during automated browser testing. This example shows how to configure Chrome options with a retrieved proxy. ```python from fp.fp import FreeProxy from fp.errors import FreeProxyException from selenium import webdriver from selenium.webdriver.chrome.options import Options def create_driver_with_proxy(): try: proxy = FreeProxy(https=True, elite=True).get() # Extract host:port from proxy string (remove 'http://' prefix) proxy_address = proxy.replace('http://', '').replace('https://', '') chrome_options = Options() chrome_options.add_argument(f'--proxy-server={proxy_address}') driver = webdriver.Chrome(options=chrome_options) return driver, proxy except FreeProxyException as e: print(f"Could not find proxy: {e.message}") return None, None # Usage driver, proxy = create_driver_with_proxy() if driver: print(f"Using proxy: {proxy}") driver.get('https://httpbin.org/ip') print(driver.page_source) driver.quit() ``` -------------------------------- ### Error Handling for Proxy Retrieval Source: https://context7.com/jundymek/free-proxy/llms.txt Implement robust error handling using try-except blocks to catch FreeProxyException when no working proxies are available. This example demonstrates retrying proxy acquisition with requests. ```python from fp.fp import FreeProxy from fp.errors import FreeProxyException import requests def get_with_proxy(url, max_retries=3): for attempt in range(max_retries): try: proxy = FreeProxy(rand=True, timeout=0.5).get() proxies = {'http': proxy, 'https': proxy} response = requests.get(url, proxies=proxies, timeout=10) return response except FreeProxyException: print(f"Attempt {attempt + 1}: No working proxy found") except requests.exceptions.RequestException as e: print(f"Attempt {attempt + 1}: Request failed - {e}") raise Exception("Failed to complete request after all retries") # Usage try: response = get_with_proxy('https://httpbin.org/ip') print(response.json()) except Exception as e: print(f"Error: {e}") ``` -------------------------------- ### Get US or GB Proxy Source: https://github.com/jundymek/free-proxy/blob/master/README.md Fetches a proxy specifically from the United States or United Kingdom. ```python proxy = FreeProxy(country_id=['US']).get() proxy = FreeProxy(country_id=['GB']).get() ``` -------------------------------- ### Get Raw Proxy List Source: https://context7.com/jundymek/free-proxy/llms.txt Retrieve an unvalidated list of proxies using `get_proxy_list()`. This is useful for custom validation or batch processing. You can specify `repeat=False` to fetch from the primary source or `repeat=True` for fallback sources. ```python from fp.fp import FreeProxy # Get unvalidated proxy list from primary source fp = FreeProxy(country_id=['US']) proxy_list = fp.get_proxy_list(repeat=False) print(f"Found {len(proxy_list)} proxies") for proxy in proxy_list[:5]: print(proxy) # Output: '192.168.1.1:8080' # Get from fallback source (free-proxy-list.net) fallback_list = fp.get_proxy_list(repeat=True) print(f"Fallback source has {len(fallback_list)} proxies") ``` -------------------------------- ### FreeProxy Initialization and Usage Source: https://github.com/jundymek/free-proxy/blob/master/README.md Demonstrates how to initialize the FreeProxy class and retrieve a working proxy. It covers basic usage and various filtering options. ```APIDOC ## FreeProxy Initialization and Usage ### Description This section details how to use the `FreeProxy` class to obtain a working proxy server. You can initialize `FreeProxy` with various parameters to filter the proxies based on your needs. ### Method GET (Implicit - retrieving a proxy) ### Endpoint N/A (This is a library, not a web API endpoint) ### Parameters #### Initialization Parameters - **country_id** (list) - Optional - A list of country codes (e.g., ['US', 'BR']) to filter proxies by. Defaults to None. - **timeout** (float > 0) - Optional - The maximum time in seconds to wait for a proxy to respond. Defaults to 0.5. - **rand** (bool) - Optional - If True, shuffles the list of proxies. Defaults to False. - **anonym** (bool) - Optional - If True, returns only anonymous proxies. Defaults to False. - **elite** (bool) - Optional - If True, returns only elite proxies (which are also anonymous). Defaults to False. - **google** (bool, None) - Optional - If True, returns only proxies marked as 'google'. If False, excludes them. Defaults to None (includes all). - **https** (bool) - Optional - If True, returns only HTTPS proxies. Defaults to False (HTTP proxies). - **url** (str) - Optional - A custom URL to use for testing proxy validity. Defaults to 'https://www.google.com'. ### Request Example ```python from fp.fp import FreeProxy # Get a proxy with default settings proxy_default = FreeProxy().get() print(f"Default Proxy: {proxy_default}") # Get a proxy from US or Brazil, with a timeout of 0.3 seconds, and randomized order proxy_custom = FreeProxy(country_id=['US', 'BR'], timeout=0.3, rand=True).get() print(f"Custom Proxy: {proxy_custom}") # Get an elite proxy proxy_elite = FreeProxy(elite=True).get() print(f"Elite Proxy: {proxy_elite}") # Get an HTTPS proxy proxy_https = FreeProxy(https=True).get() print(f"HTTPS Proxy: {proxy_https}") # Use a custom test URL proxy_custom_url = FreeProxy(url='http://httpbin.org/get').get() print(f"Custom URL Proxy: {proxy_custom_url}") ``` ### Response #### Success Response - **proxy** (str) - A string representing a working proxy, e.g., `'http://113.160.218.14:8888'` #### Response Example ``` 'http://113.160.218.14:8888' ``` ### Error Handling - If no working proxies are found with the given parameters, a `FreeProxyException` is raised with the message `There are no working proxies at this time.` ``` -------------------------------- ### Basic Usage and Integration with Requests Source: https://context7.com/jundymek/free-proxy/llms.txt Retrieve a working proxy and use it with the requests library. ```python from fp.fp import FreeProxy # Basic usage - get any working proxy proxy = FreeProxy().get() print(proxy) # Output: 'http://113.160.218.14:8888' # Use with requests library import requests proxies = {'http': proxy, 'https': proxy} response = requests.get('https://httpbin.org/ip', proxies=proxies) print(response.json()) ``` -------------------------------- ### Import FreeProxy Source: https://github.com/jundymek/free-proxy/blob/master/README.md Required import statement to use the library. ```python from fp.fp import FreeProxy ``` -------------------------------- ### Enable Random Proxy Selection Source: https://context7.com/jundymek/free-proxy/llms.txt Use the rand parameter to randomize the selection order instead of the default list order. ```python from fp.fp import FreeProxy # Get random proxy instead of first available proxy = FreeProxy(rand=True).get() # Combine with other filters proxy = FreeProxy(country_id=['US'], rand=True, timeout=0.5).get() ``` -------------------------------- ### Filter by Country Source: https://github.com/jundymek/free-proxy/blob/master/README.md Fetches a proxy from a specific list of countries. ```python proxy = FreeProxy(country_id=['US', 'BR']).get() ``` -------------------------------- ### Filter Google Proxies Source: https://github.com/jundymek/free-proxy/blob/master/README.md Returns only proxies marked as compatible with Google. ```python proxy = FreeProxy(google=True).get() ``` -------------------------------- ### Randomize Proxy Selection Source: https://github.com/jundymek/free-proxy/blob/master/README.md Shuffles the proxy list order instead of using the default newest-to-oldest order. ```python proxy = FreeProxy(rand=True).get() ``` -------------------------------- ### Filter by Google Compatibility Source: https://context7.com/jundymek/free-proxy/llms.txt Filter proxies based on their ability to access Google services. ```python from fp.fp import FreeProxy # Get only proxies that work with Google proxy = FreeProxy(google=True).get() # Get only proxies NOT marked as Google-compatible proxy = FreeProxy(google=False).get() # Default (None) returns all proxies regardless of Google status proxy = FreeProxy(google=None).get() ``` -------------------------------- ### Configure Proxy Validation Timeout Source: https://context7.com/jundymek/free-proxy/llms.txt Adjust the timeout threshold for connectivity tests. Lower values speed up selection but may exclude slower proxies. ```python from fp.fp import FreeProxy # Default timeout is 0.5 seconds proxy = FreeProxy().get() # Set longer timeout for slower networks proxy = FreeProxy(timeout=1.0).get() # Set shorter timeout for faster proxy selection proxy = FreeProxy(timeout=0.3).get() ``` -------------------------------- ### Filter by HTTPS Support Source: https://context7.com/jundymek/free-proxy/llms.txt Filter for proxies that support HTTPS connections, which can handle both HTTP and HTTPS traffic. ```python from fp.fp import FreeProxy # Get HTTPS proxy (works with both HTTP and HTTPS sites) proxy = FreeProxy(https=True).get() # Default returns HTTP proxies http_proxy = FreeProxy(https=False).get() # Combine HTTPS with other filters secure_proxy = FreeProxy(https=True, elite=True, country_id=['US']).get() ``` -------------------------------- ### Set Custom Validation URL Source: https://github.com/jundymek/free-proxy/blob/master/README.md Configures a custom URL for testing proxy validity. ```python proxy = FreeProxy().get() proxy = FreeProxy(url='http://httpbin.org/get').get() ``` -------------------------------- ### Filter Elite Proxies Source: https://github.com/jundymek/free-proxy/blob/master/README.md Returns only proxies marked as elite. ```python proxy = FreeProxy(elite=True).get() ``` -------------------------------- ### Set Proxy Timeout Source: https://github.com/jundymek/free-proxy/blob/master/README.md Configures the timeout duration for proxy validation. ```python proxy = FreeProxy(timeout=1).get() ``` -------------------------------- ### Filter Proxies by Country Source: https://context7.com/jundymek/free-proxy/llms.txt Use country_id to restrict proxies to specific regions. US and GB codes utilize dedicated regional sources. ```python from fp.fp import FreeProxy # Get proxy from specific countries proxy = FreeProxy(country_id=['US', 'BR']).get() # Get US proxy (uses dedicated us-proxy.org source) us_proxy = FreeProxy(country_id=['US']).get() # Get UK proxy (uses dedicated UK proxy list) uk_proxy = FreeProxy(country_id=['GB']).get() # Multiple countries - will try each until a working proxy is found proxy = FreeProxy(country_id=['DE', 'FR', 'NL']).get() ``` -------------------------------- ### Filter by Anonymity Level Source: https://context7.com/jundymek/free-proxy/llms.txt Select proxies based on anonymity. Elite proxies provide the highest level of privacy. ```python from fp.fp import FreeProxy # Get only anonymous proxies proxy = FreeProxy(anonym=True).get() # Get only elite proxies (highest anonymity level) # Note: elite proxies are always anonymous proxy = FreeProxy(elite=True).get() # Combine elite with country filter proxy = FreeProxy(elite=True, country_id=['US']).get() ``` -------------------------------- ### Filter HTTPS Proxies Source: https://github.com/jundymek/free-proxy/blob/master/README.md Returns only proxies marked as HTTPS. ```python proxy = FreeProxy(https=True).get() ``` -------------------------------- ### Specify Custom Validation URL Source: https://context7.com/jundymek/free-proxy/llms.txt Override the default Google validation check with a custom URL to ensure compatibility with your target service. ```python from fp.fp import FreeProxy # Test proxies against custom endpoint proxy = FreeProxy(url='http://httpbin.org/get').get() # Test against your specific target service proxy = FreeProxy(url='https://api.example.com/health').get() ``` -------------------------------- ### Filter Anonymous Proxies Source: https://github.com/jundymek/free-proxy/blob/master/README.md Returns only proxies marked as anonymous. ```python proxy = FreeProxy(anonym=True).get() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.