E
E
Ernest Vardanyan2020-06-09 20:22:01
Python
Ernest Vardanyan, 2020-06-09 20:22:01

How to finish the code correctly?

Hello everyone, if when opening the site in the match there is a score of 0:0, then he enters it and the function that is specified is turned on, the parser is already included in it, the problem is that if the match matches the condition, then it does not close the browser, I guess that there is no browser.close at the end of the parser function, but if you specify it there in the job function, then an error occurs and the computer rejects the request

from selenium import webdriver
import telegram
from selenium.common.exceptions import NoSuchElementException
import schedule
import sched, time
s = sched.scheduler(time.time, time.sleep)


def job():
    browser = webdriver.Chrome()
    browser.maximize_window()
    browser.get('какая-то ссылка')


    def games():
        BOT_TOKEN = 'токен'
        all = browser.find_element_by_class_name('u-fg').text
        Allmassif = all.split()
        if 'игрок' in Allmassif[0] and 'игрок' in Allmassif[1] and 'игрок' in Allmassif[2] and 'другой игрок' in Allmassif[5] and 'другой игрок' in Allmassif[6]:
            win = browser.find_element_by_xpath('//*[@id="allBetsTable"]/div[1]/div[1]/div/div[2]/div[1]/span[2]').text
            if win >= '1.45':
                bot = telegram.Bot(token=BOT_TOKEN)
                bot.send_message(chat_id='айди',text='\U0001F4E3 Внимание: появилась ставка \U0001F4E3' + '\n' + '\n' + '\U0001F3AE игрок1 - игрок 2' + '\n' + '\U00002B55 Ставим на победу - игрок 1' + '\n' + '\U0001F525' + ' ' + win)
                while True:
                    number = browser.find_element_by_xpath('/html/body/div[2]/div[1]/div[2]/div/div/div[2]/div/div/div/div[1]/div[1]/div/div[2]/div/div/div[2]/div/div/div[2]').text
                    SS = number.split()
                    Allmassif = all.split()
                    while SS[0] != '1' and Allmassif[0] == 'игрок':
                        time.sleep(50)
                        browser.refresh()
                        time.sleep(3)
                        number = browser.find_element_by_xpath('/html/body/div[2]/div[1]/div[2]/div/div/div[2]/div/div/div/div[1]/div[1]/div/div[2]/div/div/div[2]/div/div/div[2]').text
                        S1 = number.split()
                        all = browser.find_element_by_class_name('u-fg').text
                        S2 = all.split()
                        if S1[0] == '1':
                            bot.send_message(chat_id='айди', text='\U00002705\U00002705\U00002705 Ставка зашла')
                            break
                        elif S2[0] != 'игрок':
                            bot.send_message(chat_id='айди', text='\U0000274C Сухарь')
                            break
                        else:
                            break
                    else:
                        pass
            else:
                pass
        else:
            pass


    def match_2():
        try:
            while True:
                number = browser.find_element_by_xpath('//*[@id="games_content"]/div/div[1]/div/div/div[3]/div/div[1]/div[1]/div').text
                SS = number.split()
                if SS[0] == '0' and SS[0] == '0':
                    browser.find_element_by_xpath('//*[@id="games_content"]/div/div[1]/div/div/div[3]/div/div[1]/div[1]/a').click()
                    time.sleep(4)
                    games()
                    break
                else:
                    break
        except NoSuchElementException:
            pass


    match_2()

    browser.quit()

schedule.every(30).seconds.do(job)
job()


s.run()

while True:
    schedule.run_pending()
    time.sleep(30)


I understand that the code is terrible, but still I ask for help, do not judge, newbie

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey_Dolg, 2020-06-09
@Andrey_Dolg

UnsupportedOperation: question not readable.
And if without sarcasm, then it’s not clear what your problem is, write in more detail.
Well, if you don’t get to browser.quit()the function, then you are clearly in an infinite loop and
while True:
visually a good candidate for the role of such a loop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question