Настройки Selenium Proxy - PullRequest
       2

Настройки Selenium Proxy

0 голосов
/ 25 июня 2019

Мне нужно использовать Selenium через прокси в Python.Мой личный тип прокси: user:password:ip:port.Приведенный ниже код работает, но не имеет параметров user и password.Есть ли кто-нибудь, кто может обновить этот код?Спасибо.

from selenium import webdriver
import time


"Define Both ProxyHost and ProxyPort as String"
ProxyHost = "ip"
ProxyPort = "port"



def ChangeProxy(ProxyHost ,ProxyPort):
    "Define Firefox Profile with you ProxyHost and ProxyPort"
    profile = webdriver.FirefoxProfile()
    profile.set_preference("network.proxy.type", 1)
    profile.set_preference("network.proxy.http", ProxyHost )
    profile.set_preference("network.proxy.http_port", int(ProxyPort))
    profile.update_preferences()
    return webdriver.Firefox(firefox_profile=profile)


def FixProxy():
    "Reset Firefox Profile"
    profile = webdriver.FirefoxProfile()
    profile.set_preference("network.proxy.type", 0)
    return webdriver.Firefox(firefox_profile=profile)


driver = ChangeProxy(ProxyHost ,ProxyPort)
driver.get("http://whatismyipaddress.com")

time.sleep(5)

driver = FixProxy()
driver.get("http://whatismyipaddress.com")

1 Ответ

0 голосов
/ 25 июня 2019

Определите свой атрибут:

    username = "your_username_here" 
    password = "your_password_here"

Затем добавьте их в свои предпочтения:

    profile.set_preference("network.proxy.socks_username", username)
    profile.set_preference("network.proxy.socks_password", password)

Другой подход:

profile.set_preference('network.http.phishy-userpass-length', 255)
driver = webdriver.Firefox(firefox_profile=profile)
driver.get("https://username:password@somewebsite.com:port/")
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...