chrome和firefox driver使用代理
生活随笔
收集整理的這篇文章主要介紹了
chrome和firefox driver使用代理
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
- 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)
- 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()
總結(jié)
以上是生活随笔為你收集整理的chrome和firefox driver使用代理的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 「Log」2023.8.15 小记
- 下一篇: 「Log」做题记录 2023.7.31-