1

So I have the code below, it is still showing the real IP. No error produced either. Sorry can't share real proxy details :)

from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium.webdriver.firefox.options import Options
PROXY_HOST = "206.41.127.230"

PROXY_PORT = "603230"

USERNAME = "xxx"

PASSWORD = "xx"

profile = webdriver.FirefoxProfile()

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

profile.set_preference("network.proxy.http", PROXY_HOST)

profile.set_preference("network.proxy.http_port", PROXY_PORT)

profile.set_preference("network.proxy.socks_username", USERNAME)

profile.set_preference("network.proxy.socks_password", PASSWORD)

options = Options()
options.headless = True
driver = webdriver.Firefox(options=options, executable_path=r'/usr/local/bin/geckodriver', firefox_profile=profile)
driver.get('https://httpbin.org/ip')
html = driver.page_source
print(html)
driver.quit()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Volatil3
  • 14,253
  • 38
  • 134
  • 263

1 Answers1

2

Seems you were close. You need to invoke update_preferences() for the FirefoxProfile instance profile and you can use the following solution:

from selenium import webdriver

PROXY_HOST = "206.41.127.230"
PROXY_PORT = "6032"
USERNAME = "xxx"
PASSWORD = "xx"

profile = webdriver.FirefoxProfile()
profile.set_preference('network.proxy.type', 1)
profile.set_preference("network.proxy.http", PROXY_HOST)
profile.set_preference("network.proxy.http_port", PROXY_PORT)
profile.set_preference("network.proxy.socks_username", USERNAME)
profile.set_preference("network.proxy.socks_password", PASSWORD)
profile.update_preferences()
options = webdriver.FirefoxOptions()
options.headless = True
driver = webdriver.Firefox(options=options, executable_path=r'/usr/local/bin/geckodriver', firefox_profile=profile)
driver.get('https://httpbin.org/ip')
html = driver.page_source
print(html)
driver.quit()

References

You can find a relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 2
    Not working for me...I do not know why. It is still returning Real IP address. – Volatil3 Nov 29 '19 at 05:36
  • When I use proxies via `requests` I used the PROXY URL as `proxy_url = 'https://u:password@' + random_proxy.rstrip('\n')` - HTTPS – Volatil3 Nov 29 '19 at 05:39