Home > OS >  Shorten Selenium-Wire Option
Shorten Selenium-Wire Option

Time:03-27

I would like to improve the following case by shorting it. I've come this far

if decision == 'y':
    seleniumwire_options = {
        'proxy': {
            'http': f'https://usr:pw@page:port',
        }
    }

if decision == 'n':
    seleniumwire_options = {
        'proxy': {
            'no_proxy': 'localhost,127.0.0.1'
        }
    }

You could say that I should just remove the n decision, but I can't because I need seleniumwire_options later.

webdriver.Chrome(..., seleniumwire_options = seleniumwire_options)

CodePudding user response:

You can shorten it by factoring out common parts, like this:

if decision == 'y':
    proxy = {
        'http': f'https://usr:pw@page:port',
    }

if decision == 'n':
    proxy = {
        'no_proxy': 'localhost,127.0.0.1',
    }


seleniumwire_options = {
    'proxy': proxy
}
  • Related