How to set proxy authentication (user & password) using Python + Selenium

后端 未结 4 400
栀梦
栀梦 2020-11-30 07:52

I am using Firefox WebDriver in Python 2.7 with Selenium. My python program starts Firefox browser and visits different websites when I run the program. But, I need to set t

4条回答
  •  無奈伤痛
    2020-11-30 08:34

    Dup of: How to set proxy AUTHENTICATION username:password using Python/Selenium

    Selenium-wire: https://github.com/wkeeling/selenium-wire

    Install selenium-wire

    pip install selenium-wire
    

    Import it

    from seleniumwire import webdriver
    

    Auth to proxy

    options = {
    'proxy': {
        'http': 'http://username:password@host:port',
        'https': 'https://username:password@host:port',
        'no_proxy': 'localhost,127.0.0.1,dev_server:8080'
        }
    }
    driver = webdriver.Firefox(seleniumwire_options=options)
    

    Warning
    Take a look to the selenium-wire cache folder. I had a problem because it take all my disk space. You have to remove it sometimes in your script when you want.

提交回复
热议问题