Answer the question
In order to leave comments, you need to log in
UnboundLocalError: local variable referenced before assignment what to do?
Good afternoon, there is a parser that comes in to log in, collects information, sorts out the keys, but when sending a message to tg, an error occurs if task_stack not in known_tasks and key in task_key:
UnboundLocalError: local variable 'task_stack' referenced before assignment
tried to set global
Please tell me which way to dig .
def send_telegram(message, task):
bot.send_message(message.chat.id, task)
def func (message):
if (message.text == 'Включить Парсер'):
bot.send_message(message.chat.id, "Запускаю парсер")
leads = "n.php"
main_key = config.KEY_WORDS
url = config.URL + leads
driver = webdriver.Firefox()
driver.get(url)
login = driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/div/div[2]/div/div/form/div/div/div[1]/label/span/input')
login.send_keys(config.LOGIN)
time.sleep(0.1)
passw = driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/div/div[2]/div/div/form/div/div/div[2]/label/span/input')
passw.send_keys(config.PASSWORD)
click = driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/div/div[2]/div/div/form/a')
click.click()
time.sleep(4)
page = driver.page_source
soup = bs(page, 'html.parser')
known_tasks = []
while True:
for block in soup.find_all(class_=re.compile("OrderSnippetContainerStyles")):
task_key = block.find(class_=re.compile("SnippetBodyStyles__Content")).get_text().replace('\n', ' ')
name = block.find(class_=re.compile("StatusAndClientInfoStyles__Name")).get_text().replace('\n', ' ')
task_stack = (task_key, name)
for key in main_key:
if task_stack not in known_tasks and key in task_key:
known_tasks.append(task_key)
send_telegram(str(''.join(task_stack)))
known_tasks.append(task_stack)
time.sleep(60)
driver.get(url)
page = driver.page_source
soup = bs(page, 'html.parser')
Answer the question
In order to leave comments, you need to log in
In this line
for block in soup.find_all(class_=re.compile("OrderSnippetContainerStyles"))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question