Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running selenium behind a proxy server

I have been using selenium for automatic browser simulations and web scraping in python and it has worked well for me. But now, I have to run it behind a proxy server. So now selenium open up the window but could not open the requested page because of proxy settings not set on the opened browser. Current code is as follows (sample):

from selenium import webdriver

sel = webdriver.Firefox()
sel.get('http://www.google.com')
sel.title
sel.quit()

How do I change the above code to work with proxy server now as well?

like image 202
Aryabhatt Avatar asked Aug 01 '13 08:08

Aryabhatt


Video Answer


1 Answers

You need to set desired capabilities or browser profile, like this:

profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", "proxy.server.address")
profile.set_preference("network.proxy.http_port", "port_number")
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile)

Also see related threads:

  • how do i set proxy for chrome in python webdriver
  • Selenium using Python: enter/provide http proxy password for firefox
  • Running Selenium Webdriver with a proxy in Python
  • http://krosinski.blogspot.ru/2012/11/selenium-firefox-webdriver-and-proxies.html
like image 174
alecxe Avatar answered Oct 10 '22 20:10

alecxe