6

I am trying to access a website through selenium which is blocked in the country I live in. I am using selenium in python and using a proxy to do this. However, I noticed that once I check the IP of the opened selenium browser, it shows my real IP and not the proxy. It is a bit confusing because I managed to access this site once through the following driver settings, but it doesn't work anymore.

        fp = webdriver.FirefoxProfile()
        PROXY_PORT = config['DEFAULT']['PROXY_PORT']
        PROXY_HOST = config['DEFAULT']['PROXY_HOST']
        fp.set_preference('network.proxy.type', 0)
        fp.set_preference('network.proxy.http', PROXY_HOST)
        fp.set_preference('network.proxy.http_port', int(PROXY_PORT))
        fp.set_preference('network.proxy.https', PROXY_HOST)
        fp.set_preference('network.proxy.https_port', int(PROXY_PORT))
        fp.set_preference('network.proxy.ssl', PROXY_HOST)
        fp.set_preference('network.proxy.ssl_port', int(PROXY_PORT))
        fp.set_preference('network.proxy.ftp', PROXY_HOST)
        fp.set_preference('network.proxy.ftp_port', int(PROXY_PORT))
        fp.set_preference('network.proxy.socks', PROXY_HOST)
        fp.set_preference('network.proxy.socks_port', int(PROXY_PORT))
        fp.set_preference("general.useragent.override", "whater_useragent")
        fp.set_preference("general.useragent.override", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A")
        fp.update_preferences()
        driver = webdriver.Firefox(firefox_profile=fp)

Now, I am trying using assigning the proxy using this method but it makes no change.

    PROXY_PORT = config['DEFAULT']['PROXY_PORT']
    PROXY_HOST = config['DEFAULT']['PROXY_HOST']
    myProxy = PROXY_HOST + ':' + PROXY_PORT
    proxy = webdriver.common.proxy.Proxy({'proxyType':webdriver.common.proxy.ProxyType.MANUAL,
     'httpProxy':myProxy,
     'ftpProxy':myProxy,
     'sslProxy':myProxy})
    driver = webdriver.Firefox(proxy=proxy)

What I need is for the IP in the opened firefox browser to be that of the proxy. How can this be done? I have no idea why it worked at first an now it doesn't. Please explain.

1 Answer 1

1

Using Chrome, it's very simple:

options = webdriver.ChromeOptions()
options.add_argument('='.join(['--proxy-server', "http://localhost:8888/"]))

You can also try using an addon/extension to do this. I've had success both ways :)

In case you need a proxy server: https://github.com/ochen1/pyproxy

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.