小编Ali*_*Bom的帖子

如何在 Selenium 4.x 中将 Selenium 与 Firefox 代理结合使用

我需要传递选项,因为配置文件已被弃用。我正在尝试使用 FF 代理到安全浏览器。但是,我遇到了一个问题,如下所述:

我的代码:

from selenium import webdriver
from selenium.webdriver.common.by import By
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.common.proxy import Proxy, ProxyType

socks = '127.0.0.1:9050'
profile_path = '~/Library/Application\ Support/TorBrowser-Data/Browser/tjv18qgq.default'
capabilities = webdriver.DesiredCapabilities.FIREFOX
proxy = Proxy({
    "proxyType": 'manual',
    "httpProxy": socks,
    "sslProxy": socks,
    "noProxy": ''
})
proxy.add_to_capabilities(capabilities)
options = FirefoxOptions()
options.headless = False
options.set_preference('profile', profile_path)
options.set_capability("proxy", proxy)
service = Service(executable_path=GeckoDriverManager().install())
driver = webdriver.Firefox(service=service, options=options)

driver.get('https://check.torproject.org/')
element = driver.find_element(By.TAG_NAME, 'h1')
if element.text == 'Sorry. …
Run Code Online (Sandbox Code Playgroud)

python firefox proxy selenium geckodriver

6
推荐指数
1
解决办法
8913
查看次数

标签 统计

firefox ×1

geckodriver ×1

proxy ×1

python ×1

selenium ×1