[PHP]from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
def setup_proxy_with_auth(ip, port, username, password):
# Proxy bilgileri
proxy_address = f"{ip}:{port}"
# Chrome Options yapılandırması
chrome_options = Options()
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument(f"--proxy-server=http://{proxy_address}")
# Proxy kimlik doğrulaması için uzantı oluştur
plugin_file = create_proxy_auth_extension(ip, port, username, password)
chrome_options.add_extension(plugin_file)
# WebDriver başlat
service = Service(executable_path="chromedriver") # ChromeDriver yolunu belirtin
driver = webdriver.Chrome(service=service, options=chrome_options)
return driver
def create_proxy_auth_extension(ip, port, username, password):
import zipfile
import os
# Proxy uzantısı dosya yolu
manifest_json = """
{
"version": "1.0.0",
"manifest_version": 2,
"name": "Proxy with Auth",
"permissions": [
"proxy",
"tabs",
"unlimitedStorage",
"storage",
"<all_urls>"
],
"background": {
"scripts": ["background.js"]
}
}
"""
background_js = f"""
var config = {{
mode: "fixed_servers",
rules: {{
singleProxy: {{
scheme: "http",
host: "{ip}",
port: parseInt({port})
}},
bypassList: ["localhost"]
}}
}};
chrome.proxy.settings.set({{value: config, scope: "regular"}}, function() {{}});
chrome.webRequest.onAuthRequired.addListener(
function(details, callback) {{
callback({{authCredentials: {{username: "{username}", password: "{password}"}}}});
}},
{{urls: ["<all_urls>"]}},
["blocking"]
);
"""
# Dosyaları yazma
plugin_file_path = "proxy_auth_plugin.zip"
with zipfile.ZipFile(plugin_file_path, "w") as zp:
zp.writestr("manifest.json", manifest_json)
zp.writestr("background.js", background_js)
return plugin_file_path
# Kullanım
proxy_ip = "123.456.78.90"
proxy_port = "8080"
proxy_user = "your_username"
proxy_pass = "your_password"
driver = setup_proxy_with_auth(proxy_ip, proxy_port, proxy_user, proxy_pass)
# Test için siteye git
driver.get("https://httpbin.org/ip")[PHP]