B
B
Bergis2019-09-05 17:57:13
Python
Bergis, 2019-09-05 17:57:13

How to set proxy in selenium?

import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
import names
import random

chars = 'abcdefghijklnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
chars1 = 'abcdefghijklnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'


proxy = "62.33.207.201"
port = "80"

while True:

  profile = webdriver.FirefoxProfile()
  profile.set_preference("network.proxy.type", 1)
  profile.set_preference("network.proxy.http", proxy)
  profile.set_preference("network.proxy.http_port", port)
  profile.set_preference("network.proxy.ssl", proxy)
  profile.set_preference("network.proxy.ssl_port", port)
  profile.update_preferences()

  driver = webdriver.Firefox(executable_path="C:\\Users\\User\\AppData\\Local\\Programs\\Python\\Python37-32\\geckodriver.exe", firefox_profile=profile)
  driver.get("https://www.iplocation.net/find-ip-address")

  if __name__ == "__main__":
    unittest.main()

I'm trying to set a proxy, but something is in vain ... How to do everything right?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Yakushenko, 2019-09-05
@Bergis

proxy = '62.33.207.201:80'

caps = webdriver.DesiredCapabilities.FIREFOX
caps['marionette'] = True

caps['proxy'] = {
    "proxyType": "MANUAL",
    "httpProxy": proxy,
    "ftpProxy": proxy,
    "sslProxy": proxy
}

driver = webdriver.Firefox(capabilities=caps)

M
mangaop, 2020-03-27
@mangaop

port = "80" - is not.
port=80

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question