Skip to content

Esequiel378/proxy_randomizer

Repository files navigation

proxy-randomizer

image

Documentation Status

Total Downloads

Black Formater

proxy randomizer

Description

Inpired by http-request-randomizer

proxy_randomizer is intended to use for small-meduim web scrapers/crawlers, helping to avoid temporal/permanent bans from web pages, generating random proxies to include in the requests

Installation

pip install proxy_randomizer

API

To use proxy_randomizer in your code, you just need to generate a RegisteredProviders instance and parse the providers.

from proxy_randomizer import RegisteredProviders

rp = RegisteredProviders()
rp.parse_providers()

print(f"proxy: {rp.get_random_proxy()}")

You can iterate throughout all proxies as simple as this.

from proxy_randomizer import RegisteredProviders
import requests

rp = RegisteredProviders()
rp.parse_providers()

for proxy in rp.proxies:

     proxies     = {"https": proxy.get_proxy()}
     response    = requests.get("http://google.com", proxies=proxies)

If you need to hide your identity, you can filter the proxy list by its anonymity level.

from proxy_randomizer import RegisteredProviders
from proxy_randomizer.proxy import Anonymity

rp = RegisteredProviders()
rp.parse_providers()

anonymous_proxies = list(
    filter(lambda proxy: proxy.anonymity == Anonymity.ANONYMOUS, rp.proxies)
)

print(f"filtered proxies: {anonymous_proxies}")

There are four different anonymity levels, you can inspect them like this

from proxy_randomizer.utils import ANONYMITY_LEVELS

for level in ANONYMITY_LEVELS:
   print(level.label)

Command-line interface

If you need some quick proxy, just type this in your terminal.

proxy_randomizer

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.