I would like to improve the following case by shorting it. I’ve come this far
JavaScript
x
14
14
1
if decision == 'y':
2
seleniumwire_options = {
3
'proxy': {
4
'http': f'https://usr:pw@page:port',
5
}
6
}
7
8
if decision == 'n':
9
seleniumwire_options = {
10
'proxy': {
11
'no_proxy': 'localhost,127.0.0.1'
12
}
13
}
14
You could say that I should just remove the n
decision, but I can’t because I need seleniumwire_options
later.
JavaScript
1
2
1
webdriver.Chrome( , seleniumwire_options = seleniumwire_options)
2
Advertisement
Answer
You can shorten it by factoring out common parts, like this:
JavaScript
1
15
15
1
if decision == 'y':
2
proxy = {
3
'http': f'https://usr:pw@page:port',
4
}
5
6
if decision == 'n':
7
proxy = {
8
'no_proxy': 'localhost,127.0.0.1',
9
}
10
11
12
seleniumwire_options = {
13
'proxy': proxy
14
}
15