Python3: 用Selenium Gecko-Driver支持Socks5不可能?

问题描述 投票:0回答:1

我成功地使用了chromedriver,但我现在想使用geckodriver。如果我使用通过参数插入socks5的方法,它在geckofirefox上不能工作。

同样的代码也可以在chrome上运行...有什么办法可以让socks5在geckodriver上运行吗?

谢谢!

from selenium import webdriver
import os
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options


def test(login):
    userProfile = r"c:\Users\admin\AppData\Roaming\Mozilla\Firefox\Profiles\inpo8iou.default"
    options = Options()
    options.add_argument('--proxy-server=socks5://127.0.0.1:9955')
    geckodriver = "./geckodriver.exe"
    driver = webdriver.Firefox(options=options, executable_path=geckodriver)
    driver.get("https://whoer.net")


with open("accounts.txt", "r") as read_accounts:
    accounts = read_accounts.read().splitlines()
for account in accounts:
    login = account.split(":")
    test(login)

python-3.x selenium selenium-chromedriver geckodriver browser-automation
1个回答
0
投票

试着用下面的方法来做

from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType

prox = Proxy()
prox.proxy_type = ProxyType.MANUAL
prox.http_proxy = "ip_addr:port"
prox.socks_proxy = "ip_addr:port"

capabilities = webdriver.DesiredCapabilities.CHROME
prox.add_to_capabilities(capabilities)
driver = webdriver.Chrome(desired_capabilities=capabilities)# change to gecko/firefox here

你可以看到 此处 以获得更多的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.