M
M
Mazahaha2020-05-17 09:33:41
Python
Mazahaha, 2020-05-17 09:33:41

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()


It does not show an error, but even after switching to dakdakgo nothing happens, it does not search for fields and does not click. How to make a banal check

if if you went to the site, then we work further according to the algorithm
else did not go to the site, repeat the opening of the proxy and go to the site again and work further according to the algorithm

This is how it should be

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Arseny, 2020-05-17
Matytsyn @ArsenyMatytsyn

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.

N
NitroDesktop, 2020-05-17
@NitroDesktop

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

R
Rais, 2020-05-17
@0pauc0

if driver == driver.get('...

driver is compared to the object that driver creates?
Maybe there is a mistake here?

1
1 2, 2020-05-17
@weRifiCatoR

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 question

Ask a Question

731 491 924 answers to any question