Selenium
Python + Chrome
from selenium import webdriverfrom selenium.webdriver.chrome.options import Options
PROXY = "connect.trueproxies.com:8080"
chrome_options = Options()chrome_options.add_argument(f"--proxy-server=http://{PROXY}")
driver = webdriver.Chrome(options=chrome_options)driver.get("https://httpbin.org/ip")print(driver.page_source)driver.quit()import zipfilefrom selenium import webdriverfrom selenium.webdriver.chrome.options import Options
PROXY_HOST = "connect.trueproxies.com"PROXY_PORT = 8080PROXY_USER = "your_username"PROXY_PASS = "your_password"
manifest_json = """{"version":"1.0.0","manifest_version":2,"name":"Proxy","permissions":["proxy","tabs","unlimitedStorage","storage","<all_urls>","webRequest","webRequestBlocking"],"background":{"scripts":["background.js"]}}"""
background_js = """var config = {mode:"fixed_servers",rules:{singleProxy:{scheme:"http",host:"%s",port:parseInt(%s)},bypassList:["localhost"]}};chrome.proxy.settings.set({value:config,scope:"regular"},function(){});function callbackFn(details){return{authCredentials:{username:"%s",password:"%s"}};}chrome.webRequest.onAuthRequired.addListener(callbackFn,{urls:["<all_urls>"]},["blocking"]);""" % (PROXY_HOST, PROXY_PORT, PROXY_USER, PROXY_PASS)
pluginfile = "proxy_auth_plugin.zip"with zipfile.ZipFile(pluginfile, "w") as zp: zp.writestr("manifest.json", manifest_json) zp.writestr("background.js", background_js)
chrome_options = Options()chrome_options.add_extension(pluginfile)
driver = webdriver.Chrome(options=chrome_options)driver.get("https://httpbin.org/ip")print(driver.page_source)driver.quit()Python + Firefox
from selenium import webdriverfrom selenium.webdriver.firefox.options import Options
PROXY_HOST = "connect.trueproxies.com"PROXY_PORT = 8080
options = Options()options.set_preference("network.proxy.type", 1)options.set_preference("network.proxy.http", PROXY_HOST)options.set_preference("network.proxy.http_port", PROXY_PORT)options.set_preference("network.proxy.ssl", PROXY_HOST)options.set_preference("network.proxy.ssl_port", PROXY_PORT)
driver = webdriver.Firefox(options=options)driver.get("https://httpbin.org/ip")print(driver.page_source)driver.quit()Country Targeting
Use the username parameter:
PROXY_USER = "your_username-country-us"