Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'FirefoxProfile' object has no attribute 'set_proxy'

Hi I'm trying to run this:

from browsermobproxy import Server
server = Server('path')
server.start()
proxy = server.create_proxy()

from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)

proxy.new_har("google")
driver.get("http://www.google.co.in")

server.stop()
driver.quit()

But I'm getting this: AttributeError: 'FirefoxProfile' object has no attribute 'set_proxy'

I'm not sure why but everywhere I look people use profile.set_proxy(proxy.selenium_proxy())

like image 880
user16838936 Avatar asked Jul 03 '26 20:07

user16838936


1 Answers

Ok this is solved.

In modern version of Selenium, set_proxy() does not exist anymore. You need to pass the proxy in the options, as such :

from browsermobproxy import Server
server = Server('[path to binary file]')
server.start()
proxy = server.create_proxy()
# proxy.new_har('new_har_file', options={'captureHeaders': True, 'captureContent': True}) # Optional, depending what you want to do

from selenium import webdriver

# Example for Firefox :
options = webdriver.firefox.options.Options()
options.add_argument(f'--proxy-server={proxy.proxy}')
driver = webdriver.Firefox(options=options)

# And similar for Chrome driver...

Hope it helps !

like image 82
Jean Lescut Avatar answered Jul 09 '26 16:07

Jean Lescut



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!