The code of the bot that responds to new vacancies on the site. I used the asynchronous version of schedule - aioschedule so that the function action was repeated every 3 minutes. However, after the first execution, an error occurs "AttributeError: 'Dispatcher' object has no attribute 'answer' " tell me how to fix it.
`
@dp.message_handler(commands="start")
async def start(message: types):
await bot.send_message(message.chat.id, 'Choose a specialty')
@dp.message_handler()
async def launch(message: types.Message):
await message.answer('The request is being processed...')
"""Sending a request to the server"""
opt = Options()
opt.add_experimental_option("debuggerAddress", "localhost:8989")
driver = webdriver.Chrome(executable_path=r"C:\Users\vusi4\Desktop\chromedriver_win32 (1)",
chrome_options=opt)
driver.get("https://spb.hh.ru/")
"""Text transmitted by the user"""
user_msg = message.text
"""Парсинг данных"""
input_tab = driver.find_element(By.XPATH, "//*[@id='a11y-search-input']")
input_tab.send_keys(user_msg)
input_tab.send_keys(Keys.ENTER)
with open('vacancy.json', encoding='utf-8') as f:
data = json.load(f)
respond = {}
jobs = driver.find_elements(By.CSS_SELECTOR, "[class='serp-item']")
for job in jobs:
link = job.find_element(By.CSS_SELECTOR, "[data-qa='serp-
item__title']").get_attribute('href')
post_id = re.sub(r'\D', '', link)
if post_id in data:
continue
else:
link = job.find_element(By.CSS_SELECTOR, "[data-qa='serp-
item__title']").get_attribute('href')
post_id = re.sub(r'\D', '', link)
title = job.find_element(By.CSS_SELECTOR, "[data-qa='serp-item__title']").text
experience = job.find_element(By.CSS_SELECTOR,
"[data-qa='vacancy-serp__vacancy-work-experience']").text
data[post_id] = {'name': title,
'link': link,
'experience': experience
}
respond[post_id] = {'name': title,
'link': link,
'experience': experience
}
sleep(4)
# the code that responds to new vacancies
job.find_element(By.CSS_SELECTOR, "[data-qa='vacancy-serp__vacancy_response']").click()
sleep(2)
await message.answer('There is a new response')
with open("vacancy.json", "w", encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=4)
await message.answer(
'No new vacancies have been found yet.
You can look at the previously sent responses follow the link below',
reply_markup = go_to_responses)
async def scheduler(message: types.Message):
aioschedule.every(3).minutes.do(launch, message=message)
while True:
await aioschedule.run_pending()
await asyncio.sleep(2)
async def on_startup(message: types.Message):
asyncio.create_task(scheduler(message=message))
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=False,
on_startup=on_startup)
`