1. chrome chromedriver使用代理示例
from selenium import webdriver
from selenium.webdriver import DesiredCapabilities

option = webdriver.ChromeOptions()
caps = DesiredCapabilities.CHROME.copy()
caps['acceptSslCerts'] = True
caps['acceptInsecureCerts'] = True
option.add_argument(f"--proxy-server={123.43.55.1:8000}")
driver = webdriver.Chrome(r'D:\software\chromedriver.exe', options=option, desired_capabilities=caps)

 

  1. firefox geckodriver使用代理示例
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary


new_driver_path = r'D:\software\firefox\geckodriver.exe'
new_binary_path = r'D:\software\firefox\firefox.exe'
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", str(proxy_ip))
profile.set_preference("network.proxy.http_port", int(proxy_port))
profile.set_preference("network.proxy.ssl", str(proxy_ip))
profile.set_preference("network.proxy.ssl_port", int(proxy_port))
profile.set_preference("network.proxy.ftp", str(proxy_ip))
profile.set_preference("network.proxy.ftp_port", int(proxy_port))
profile.set_preference("network.proxy.socks", str(proxy_ip))
profile.set_preference("network.proxy.socks_port", int(proxy_port))
profile.set_preference("network.http.use-cache", False)
profile.update_preferences()
binary = FirefoxBinary(new_binary_path)
driver = webdriver.Firefox(firefox_profile=profile, firefox_binary=binary, executable_path=new_driver_path,
                                   options=option)
driver.maximize_window()

 

 

posted on 2023-01-13 17:59  落叶虽美只活一世  阅读(356)  评论(0编辑  收藏  举报
Live2D