Home > Back-end >  Selenium Python Proxy
Selenium Python Proxy

Time:12-23

I want to use proxy with selenium, I watched the video from youtube how to do it, but it doesn't work. This is my code:

import names
import time as t
import random
import requests
import pyautogui
import smsactivateru
import tkinter as tk
import sys
import socket
from selenium import webdriver
from selenium.webdriver.common.proxy import *
from webdriver_manager.microsoft import EdgeChromiumDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import Select
from smsactivateru import Sms, SmsTypes, SmsService, GetBalance, GetFreeSlots, GetNumber
from fake_useragent import UserAgent


options = webdriver.FirefoxOptions()
# set useragent
ua = UserAgent()
options.set_preference("general.useragent.override",ua.random)
# set proxy

firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
proxy = '91.214.31.234:8080'
firefox_capabilities['proxy'] = {
    "proxyType": "MANUAL",
    "httpProxy": proxy,
    "ftpProxy": proxy,
    "sslProxy": proxy
}



driver = webdriver.Firefox(options=options, proxy=proxy, capabilities=firefox_capabilities)

driver.get('https://2ip.ru')
t.sleep(5)

Why proxy doesn't work? Please help me. Kind people

CodePudding user response:

The following code works for me in chrome.

PROXY = '91.214.31.234:8080'
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % PROXY)
chrome = webdriver.Chrome(options=chrome_options)
chrome.get("https://www.icanhazip.com")
  • Related