0

I am trying to write a very simple script that takes a proxy (that does not need authentication) from a txt file and opens a browser with it, and then loops this action for a certain amount of times going down the proxy list. I do know how to open a txt file and use it, my main problem is getting the proxies to work. I have seen similar questions asked and I have taken the solutions and tried them, and I can get them to run without errors but the browser opens and there is no proxy. I am sure this is a very simple task, but I am very new to python and I have not gotten it to work. Thanks!

This is what I used; there are no errors but when the browser opens in IP chicken it shows my IP, not the proxy (this is just for 1 browser not the loop I was talking about):

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

options = webdriver.ChromeOptions()

proxy = Proxy()
proxy.proxyType = ProxyType.MANUAL
proxy.autodetect = False
proxy.httpProxy = proxy.sslProxy = proxy.socksProxy = "96.70.52.227:48324"
options.Proxy = proxy
options.add_argument("ignore-certificate-errors")


driver = webdriver.Chrome('/Users/aiden/Downloads/chromedriver', options=options)
driver.get('https://www.ipchicken.com/')
user13241697
  • 43
  • 1
  • 5
  • 1
    Does this answer your question? [Running Selenium Webdriver with a proxy in Python](https://stackoverflow.com/questions/17082425/running-selenium-webdriver-with-a-proxy-in-python) – AMC Apr 07 '20 at 19:10

2 Answers2

1

Try below solution:

from selenium import webdriver

PROXY = "96.70.52.227:48324" #  HOST:PORT

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % PROXY)
chrome_options.add_argument("ignore-certificate-errors")

chrome = webdriver.Chrome(options=chrome_options)
chrome.get("https://www.ipchicken.com/")
SeleniumUser
  • 4,065
  • 2
  • 7
  • 30
0

Why not just pass the proxy as a CL argument?

from selenium import webdriver


options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=127.0.0.1:9021")

driver = webdriver.Chrome(options=options)
Robert Kearns
  • 1,631
  • 1
  • 8
  • 15