如何更改 geckodriver 的代理?
How can I change geckodriver's proxy?
我需要在开始编写代码时更改 Firefox 驱动程序的代理,因为我的项目在任何网站上创建了大量帐户,并且某些网站会阻止它,例如 Instagram,我需要更改此问题的代理。我该怎么做?
从 FireFox 配置文件更改设置可能就是您要查找的内容
webdriver.FirefoxProfile()
from selenium import webdriver
# myProxy = "127.0.0.1:9150"
myProxy = "192.168.103.1:1081"
ip, port = myProxy.split(":")
fp = webdriver.FirefoxProfile()
fp.set_preference('network.proxy.type', 1)
fp.set_preference('network.proxy.socks', ip)
fp.set_preference('network.proxy.socks_port', int(port))
driver = webdriver.Firefox(fp)
从那里您可以通过调用 .set_preference()
轻松更改设置
来自 official doc
的代理的另一种方式
from selenium import webdriver
PROXY = "<HOST:PORT>"
webdriver.DesiredCapabilities.FIREFOX['proxy'] = {
"httpProxy": PROXY,
"ftpProxy": PROXY,
"sslProxy": PROXY,
"proxyType": "MANUAL",
}
with webdriver.Firefox() as driver:
# Open URL
driver.get("https://selenium.dev")
我需要在开始编写代码时更改 Firefox 驱动程序的代理,因为我的项目在任何网站上创建了大量帐户,并且某些网站会阻止它,例如 Instagram,我需要更改此问题的代理。我该怎么做?
从 FireFox 配置文件更改设置可能就是您要查找的内容
webdriver.FirefoxProfile()
from selenium import webdriver
# myProxy = "127.0.0.1:9150"
myProxy = "192.168.103.1:1081"
ip, port = myProxy.split(":")
fp = webdriver.FirefoxProfile()
fp.set_preference('network.proxy.type', 1)
fp.set_preference('network.proxy.socks', ip)
fp.set_preference('network.proxy.socks_port', int(port))
driver = webdriver.Firefox(fp)
从那里您可以通过调用 .set_preference()
轻松更改设置来自 official doc
的代理的另一种方式from selenium import webdriver
PROXY = "<HOST:PORT>"
webdriver.DesiredCapabilities.FIREFOX['proxy'] = {
"httpProxy": PROXY,
"ftpProxy": PROXY,
"sslProxy": PROXY,
"proxyType": "MANUAL",
}
with webdriver.Firefox() as driver:
# Open URL
driver.get("https://selenium.dev")