[Python] Anyone Have Proxy Script Working For FireFox / Selenium?

apex1

Regular Member
Joined
May 29, 2015
Messages
217
Reaction score
182
I tried a few scripts from stackoverflow and they don't work..

My proxies have no username and password btw.

I'm using the latest version of Python, FireFox and Selenium.
 
This is my script..

It gives no errors but leaks my IP...
Code:
from selenium import webdriver

proxy = "166.88.124.111"
port = "3111"

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:\Program Files\Mozilla Firefox\geckodriver.exe", firefox_profile=profile)
driver.get("https://www.iplocation.net/find-ip-address")

I'm using the latest version of FF, Python and Selenium.

Edit: it's updating the proxy in FF options but the port field is blank. If I manually enter the port the proxy works.
 
Last edited:
I copied code off stackoverflow and got it to work with socks proxies with no logins under chrome in C#.


I had to use new OpenQA.Selenium.Chrome.Chromeoptions() and new OpenQA.Selenium.Proxy() and then add the proxy parameters before launching chromedriver. Never tried it with http proxies or in python but the syntax should be similar.
 
I tried a few scripts from stackoverflow and they don't work..

My proxies have no username and password btw.

I'm using the latest version of Python, FireFox and Selenium.
Now that i think about it why not just make firefox use a specific port and use a program to host the proxy through that port? Most of the proxy switchers/checkers can host them
 
Integrating Firefox can be a pain in the ass sometimes.

1. Consider setting Firefox to "Use system proxy settings" then use InternetSetOption in your software (or make the software change the registry key)?

2. I'm looking at your script above. Go to "about:config" and type "network.proxy" in the filter. I noticed you didn't use "network.proxy.socks" and "network.proxy.socks_port". Have you tried these? Some other variables in there too you may want to review.
 
Maybe try it like this: https://stackoverflow.com/q/17082425/4964331. I'd suggested this to a friend earlier it worked for him.
Also, just a heads up. https://whatismyip.com and perhaps https://www.iplocation.net/find-ip-address as well do frontend check using Javascript. So it can know your real IP even when you use the most opaque proxies.
To avoid frontend detection, either disable javascript or use a VPN instead.
To only check whether Firefox is using the proxies, use https://icanhazip.com.
 
Maybe try it like this: https://stackoverflow.com/q/17082425/4964331. I'd suggested this to a friend earlier it worked for him.
Also, just a heads up. https://whatismyip.com and perhaps https://www.iplocation.net/find-ip-address as well do frontend check using Javascript. So it can know your real IP even when you use the most opaque proxies.
To avoid frontend detection, either disable javascript or use a VPN instead.
To only check whether Firefox is using the proxies, use https://icanhazip.com.

I wasn't able to get it to work. I'm not sure if the problem is selenium / geckodriver or python, but that post is 4+ years old and it doesn't work with the versions that I use. I think maybe I'd have to go down to an old version, and would like to avoid that if possible.
 
Last edited:
try this
Code:
profile = FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", proxyip)
profile.set_preference("network.proxy.http_port", proxyport)
profile.set_preference("network.proxy.ssl", proxyip)
profile.set_preference("network.proxy.ssl_port", proxyport)
driver= webdriver.Firefox(profile)
 
This is my script..

It gives no errors but leaks my IP...
Code:
from selenium import webdriver

proxy = "166.88.124.111"
port = "3111"

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:\Program Files\Mozilla Firefox\geckodriver.exe", firefox_profile=profile)
driver.get("https://www.iplocation.net/find-ip-address")

I'm using the latest version of FF, Python and Selenium.

Edit: it's updating the proxy in FF options but the port field is blank. If I manually enter the port the proxy works.
This block of code works fine, but port field has to be numeric:
port = int("3111")

Because of that you are getting that field blank.
 
When you say it's still leaking your IP, how did you determine it's leaking it still? Some site?
 
That's pretty much how your proxy needs to be set up. You should check your proxy itself.. It's possible that your proxy is sending your IP via X-Forwarded-For or Via headers. If it's so, you should use different proxies.
 
Found this thread while searching Python and Selenium FireFox Profile Proxy Help. Trying to make this Python and Selenium FireFox Profile Proxy script work. It works well with the actual proxy as a string but I can't pass the scrapped variable proxy from the proxy site to the firefox profile.

You can see what I tried in the commented out lines. Trying to figure this out so I can complete this Python and Selenium FireFox Profile Proxy project. I'll report back.

Code:
###############################################################################

# MIPYTHON .com PYTHON PROXY SCRAPE and GO SCRIPT in SELENIUM

###############################################################################

from selenium import webdriver

import time

print("*" * 60)

print("MIPYTHON .com PYTHON PROXY SCRAPE and GO SCRIPT in SELENIUM")

print("*" * 60)



browser = webdriver.Firefox()

proxy_website = "https://free-proxy-list.net/"

target_website = "https://www.whatismyip.com"

### SCRAPE PROXY

browser.get(proxy_website)

browser.find_element_by_xpath('/html/body/header/div[1]/div/div[1]/div/div/a[2]').click()

proxy = browser.find_element_by_xpath('/html/body/section[1]/div/div[2]/div/div[2]/div/table/tbody/tr[1]/td[1]').text

print(proxy)

proxy_port = browser.find_element_by_xpath('/html/body/section[1]/div/div[2]/div/div[2]/div/table/tbody/tr[1]/td[2]').text

print(proxy_port)

### USE PROXY

#proxy = "89.23.19.143"

#proxy_port = 8080

#proxy = int(proxy)

#proxy_port = int(proxy_port)

#proxy = str(proxy)

#proxy_port = str(proxy_port)

proxy_profile = webdriver.FirefoxProfile()

proxy_profile.set_preference("network.proxy.type", 1)

proxy_profile.set_preference("network.proxy.http", proxy )

proxy_profile.set_preference("network.proxy.http_port", proxy_port)

proxy_profile.set_preference("network.proxy.ssl", proxy )

proxy_profile.set_preference("network.proxy.ssl_port", proxy_port)

browser = webdriver.Firefox(firefox_profile=proxy_profile)

target_website = browser.get(target_website)
 
for firefox you can try
profile = FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", proxyip)
profile.set_preference("network.proxy.http_port", proxyport)
profile.set_preference("network.proxy.ssl", proxyip)
profile.set_preference("network.proxy.ssl_port", proxyport)
driver= webdriver.Firefox(profile)
 
@MAG WEB DESIGNS
Hey MAG, i been working on selenium for while now, using Firefox and Selenium + gecko driver . i dont know if you know but we can use gecko driver to access anything except google. i try proxies to access google with gecko Firefox and always come to capcha site. If I just fire up pure Firefox without gecko and manual change the proxies then there will be no capcha. Lead me to wonder if there is a way to go thru Firefox without gecko or another browser. have you experiences this issue ? Thanks
 
This block of code works fine, but port field has to be numeric:
port = int("3111")

Because of that you are getting that field blank.

My Bad sxiclub already answered this....

@MAG WEB DESIGNS
Hey MAG, i been working on selenium for while now, using Firefox and Selenium + gecko driver . i dont know if you know but we can use gecko driver to access anything except google. i try proxies to access google with gecko Firefox and always come to capcha site. If I just fire up pure Firefox without gecko and manual change the proxies then there will be no capcha. Lead me to wonder if there is a way to go thru Firefox without gecko or another browser. have you experiences this issue ? Thanks

Don't access Google with dirty proxies all free proxies are dirty. Try headless with phantom JS though support is discontinued?
 
My Bad sxiclub already answered this....



Don't access Google with dirty proxies all free proxies are dirty. Try headless with phantom JS though support is discontinued?
Im not sure on phantomJS part but ill look into headless firefox. I use Gimmeproxy subcription, they are public proxies btw, it weird since the same proxy with gecko would get caught and not caught if manually input into firefox.
 
This is my script..

It gives no errors but leaks my IP...
Code:
xxxxxxx

I'm using the latest version of FF, Python and Selenium.

Edit: it's updating the proxy in FF options but the port field is blank. If I manually enter the port the proxy works.
how about give int value in port like "int(port)"
that port value must be integer.
 
Back
Top