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())
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 !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With