FreeProxy

repository·master·Indexed 19 days ago

https://github.com/charlespikachu/freeproxy

A Python-based utility for automating the discovery, verification, and updating of free proxy lists. It supports HTTP, HTTPS, SOCKS4, and SOCKS5 protocols, allowing users to filter proxies by geography, anonymity level, and speed. The library includes a ProxiedSessionClient that acts as a requests.Session with an automated proxy pool and replenishment system.

Tokens
6.4K
Snippets
12
Records
17
Agent score
66%

What's inside pyfreeproxy

  1. Introduction to FreeProxy

    master

    FreeProxy is a tool designed to continuously discover, verify, and update free proxy lists. It supports multiple protocols including HTTP, HTTPS, SOCKS4, and SOCKS5.

    Users can filter discovered proxies based on several criteria to match their specific requirements, such as:

    • Geography
    • Anonymity level
    • Speed
    • And other metadata-driven attributes.
  2. Apply stricter filtering to scraped proxies

    master

    By default, freeproxy validates format and de-duplicates results. To enforce specific requirements for geography, anonymity, or speed, pass a filter_rule dictionary to the session constructor.

    Supported filter_rule keys:

    • country_code: A list of country codes, e.g., ['CN'] or ['US'].
    • anonymity: A string or list of anonymity levels: elite, anonymous, or transparent.
    • protocol: A string or list of protocols: http, https, socks4, or socks5.
    • max_tcp_ms: Maximum allowed TCP connect latency in milliseconds.
    • max_http_ms: Maximum allowed HTTP request latency to the test_url in milliseconds.

    Note on performance: Using max_tcp_ms or max_http_ms will slow down the scraping process because every proxy must be actively tested against the latency constraints.

    from freeproxy.modules.proxies import SpysoneProxiedSession
    
    # Example: US-based elite proxies
    sess = SpysoneProxiedSession(filter_rule={"anonymity": ["elite"], "country_code": ["US"]})
    sess.refreshproxies()
    print(sess.getrandomproxy(proxy_format="freeproxy"))
  3. Scrape and summarize proxies from multiple sources

    master

    You can use BuildProxiedSession to create a session for a specific source and call refreshproxies() to retrieve a list of ProxyInfo objects. To manage multiple sources, iterate through a list of source names, build a session for each, and collect the results. The ProxyInfo objects can be converted to dictionaries using .todict() for easy JSON serialization.

    import json
    from freeproxy.modules import BuildProxiedSession
    
    SOURCES = ["ProxiflyProxiedSession", "KuaidailiProxiedSession"]
    
    def scrape(src: str):
        try:
            # Build session with configuration
            sess = BuildProxiedSession({"max_pages": 1, "type": src, "disable_print": False})
            return sess.refreshproxies()
        except Exception:
            return []
    
    free_proxies = {}
    for src in SOURCES:
        proxies = scrape(src)
        # Convert ProxyInfo objects to dicts for JSON saving
        free_proxies[src] = [p.todict() for p in proxies]
    
    with open("free_proxies.json", "w") as f:
        json.dump(free_proxies, f, indent=2)
  4. Scrape proxies from multiple sources

    master

    You can use BuildProxiedSession to scrape proxies from various sources. By specifying a type (the source name) and configuration like max_pages, you can retrieve a list of ProxyInfo objects. This allows you to aggregate proxies from multiple providers, summarize their statistics (protocol distribution, anonymity, etc.), and save them to a JSON file using the todict() method on each proxy object.

    import json
    from freeproxy.modules import BuildProxiedSession
    
    # Example: Scrape from a specific source
    # 'type' corresponds to the registered module name
    sess = BuildProxiedSession({"max_pages": 1, "type": "ProxiflyProxiedSession", "disable_print": False})
    proxies = sess.refreshproxies()
    
    # Save to JSON
    free_proxies = {src: [p.todict() for p in proxies] for src in ["ProxiflyProxiedSession"]}
    with open("free_proxies.json", "w") as f:
        json.dump(free_proxies, f, indent=2)
  5. Install FreeProxy from GitHub repository

    master

    You can install FreeProxy directly from the GitHub master branch or by cloning the repository manually.

    # Method 1: Install directly via git
    pip install git+https://github.com/CharlesPikachu/freeproxy.git@master
    
    # Method 2: Clone and install via setup.py
    git clone https://github.com/CharlesPikachu/freeproxy.git
    cd freeproxy
    python setup.py install
  6. List all supported proxy sources

    master

    To see which proxy sources are available in your current version of freeproxy, you can inspect the REGISTERED_MODULES dictionary on the ProxiedSessionBuilder class.

    python -c "from freeproxy.modules import ProxiedSessionBuilder; print(ProxiedSessionBuilder.REGISTERED_MODULES.keys())"
  7. Install pyfreeproxy

    master

    You can install pyfreeproxy using pip from PyPI, directly from the GitHub repository, or by cloning the repository and running the setup script manually.

    # from pip
    pip install pyfreeproxy
    
    # from github repo method-1
    pip install git+https://github.com/CharlesPikachu/freeproxy.git@master
    
    # from github repo method-2
    git clone https://github.com/CharlesPikachu/freeproxy.git
    cd freeproxy
    python setup.py install
  8. DrissionPage dependency for certain proxy sources

    master

    Some proxy sources, such as IP3366ProxiedSession, require crawling via DrissionPage.

    If DrissionPage cannot locate a suitable browser in your environment, it will automatically attempt to download the latest compatible beta version of Google Chrome for your system. Seeing a browser download during execution is expected behavior if a browser is not already present.

  9. Note on DrissionPage and browser downloads

    master

    Some proxy sources, such as IP3366ProxiedSession, require crawling via DrissionPage.

    If DrissionPage cannot locate a suitable browser in your environment, it will automatically download the latest compatible beta version of Google Chrome for your system. If you observe the program downloading a browser during execution, this is expected behavior.

  10. Explore project examples in the Playground

    master

    The Playground section contains real-world examples of the freeproxy project in action. One notable example is the ICU996 project, which demonstrates how to process and analyze data from WeChat articles (specifically regarding the '996' work culture discussion). You can find the source code and implementation details for this example in the repository's examples/ICU996 directory.

    https://github.com/CharlesPikachu/freeproxy/tree/master/examples/ICU996