Skip to main content

Wrapper around selenium and requests to make it easier to use proxies.

Project description

t-proxy-toolkit

A wrapper around rpaframework selenium driver to enable proxy usage with Oxylabs. You can also use this tool to start a request session using Oxylabs.

Installation

Install using pip:

pip install t-proxy-toolkit

Usage

Browser Usage

Instead of creating a selenium object directly from rpaframework, use this library's chrome or firefox methods. You can optionally provide initialization preferences or options for the browser as a dictionary.

By default, the browser will be assigned a custom UserAgent using the fake-useragent package with these settings:

from fake_useragent import UserAgent

user_agent = UserAgent(os="windows", min_percentage=1.3)

# For chrome
user_agent.chrome

# For firefox
user_agent.firefox

Warning: Headless mode cannot be used when installing browser extensions

Basic usage example:

from t_proxy import BrowserProxy
from RPA.Browser.Selenium import Selenium

browser_proxy = BrowserProxy()

# Proxy credentials
user = "your_username"
password = "your_password" 
host = "proxy.host.com"
port = "12345"

# Initialize browsers - type hints added for better IDE support
firefox: Selenium = browser_proxy.firefox(user, password, host, port)
chrome: Selenium = browser_proxy.chrome(user, password, host, port)

You can create a new user for metrics and usage tracking in the Oxylabs dashboard.

Browser Configuration

Firefox Preferences

You can configure Firefox by passing a preferences dictionary. Reference the following Mozilla documentation for available preferences:

Example:

prefs = {
    "download.default_directory": "/path/to/downloads",
    "browser.download.folderList": 2
}

firefox: Selenium = browser_proxy.firefox(user, password, host, port, prefs)

Chrome Options

For Chrome, you can pass selenium ChromeOptions. Reference these resources for available options:

Example:

from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")

chrome: Selenium = browser_proxy.chrome(user, password, host, port, options)

Requests Usage

Use Oxylabs proxy servers with Python requests. The proxy behavior depends on the port:

  • Port 8000: Returns a different IP for each request
  • Ports 8001-8010: Uses a fixed IP for all requests

IPs can be managed through the Oxylabs dashboard.

Example:

from t_proxy import RequestsProxy
from requests import Session

# Proxy configuration
creds = {
    "login": "your_username",
    "password": "your_password",
    "port": "8000"  # or 8001-8010 for fixed IP
}

requests_proxy = RequestsProxy()
session: Session = requests_proxy.session(creds)

# Make requests
response = session.get("https://api.ipify.org?format=json")
print(response.json())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

t_proxy_toolkit-0.2.1.tar.gz (552.7 kB view details)

Uploaded Source

File details

Details for the file t_proxy_toolkit-0.2.1.tar.gz.

File metadata

  • Download URL: t_proxy_toolkit-0.2.1.tar.gz
  • Upload date:
  • Size: 552.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for t_proxy_toolkit-0.2.1.tar.gz
Algorithm Hash digest
SHA256 3d861fc6372c2f1fbe22324e6f7447df636696b08cb882a2867594b84cf09929
MD5 ff057e9495fc20109228fdae651de8a6
BLAKE2b-256 3b1aebce35bc1bb91d6a05f1a6e470df0c8122d385e9c8cb1555a89a84f443f4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page