M
M
Mazahaha2020-05-13 23:52:11
Python
Mazahaha, 2020-05-13 23:52:11

How to perform validation in python?

I am doing a try check. Tell me right? Bottom line:
You need to check the proxy, it seems to be set so that if the proxy worked, then the site opened and the css selector webdriver found, then we continue to work. Did you put it in correctly? And how else to add that if the selector is not found, then you need to perform the actions in the try block again

proxy_list = []
try:
    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/')
    pole_search = driver.find_element_by_css_selector('#search_form_input_homepage')
    pole_search.click()
except:
    pole_search = driver.find_element_by_css_selector('#search_form_input_homepage')
    pole_search.click()
    pass 
(Если это верно, то дальше должен быть код, который повторяет действие, если селектор не найден)

# дальше продолжаем скрипт

time.sleep(2)
pole_search.send_keys('Пикабу')

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question