Answer the question
In order to leave comments, you need to log in
How to do an if else check in Python?
Good afternoon. Please tell me how to execute a banal if else in python. Logically, it should work, as I did, in the same c # it works, but nothing happens here
proxy_list = []
with open('proxy.txt') as file:
proxy_list = file.read().splitlines()
PROXY = random.choice(proxy_list)
ch_options = webdriver.ChromeOptions()
ch_options.add_argument('--proxy-server=%s'%PROXY)
driver = webdriver.Chrome(options=ch_options)
driver.get('https://duckduckgo.com/')
if driver == driver.get('https://duckduckgo.com/'):
pole_search = driver.find_element_by_css_selector('#search_form_input_homepage')
pole_search.click()
Answer the question
In order to leave comments, you need to log in
Well, for a change, you can try to catch the error with the try → except construct in order to understand what exactly is not happening for you.
In general, in Python, the if else construct differs significantly from other PLs only in the “middle link”, which is elif (this is short for else if). Well, ternaries are written funny.
First, it is better to output print(driver) and print(driver.get(' https://duckduckgo.com/ ')) so it will be clear what is compared and why it does not work
if driver == driver.get('...
Here is an example code if else
a = int(input("введите число: ")) #вводим любое число
if a < 0: # указываем если число меньше 0, то
print("вы ввели число меньше 0") #выводим "вы ввели число меньше 0"
elif a == 0: #если же число равно нулю, то
print("вы ввели 0") #выводим "вы ввели 0"
else: #если же число не больше нуля, и не равно нулю, то
print("вы вели число больше 0") #выводим "вы вели число больше 0"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question