ipgroy
@ipgroy

ImportError: cannot import name 'Filters' from 'telegram.ext Почеу так?

Я создал бота в телеграме, но скрипт не работает почему-то и выдает мне такую ошибку. Учитывая что я обновил библиотеку.
Заменял с Filters на filters - ничего. В чем может быть прична?

import requests
from bs4 import BeautifulSoup
import telegram

# Replace 'TOKEN' with your own Telegram bot token
bot = telegram.Bot('token')

# Function that searches for job postings based on a job title
def search_jobs(job_title):
    # URL to search for job postings with the given job title on hh.ru
    url = f'https://hh.ru/search/vacancy?area=1&fromSearchLine=true&st=searchVacancy&text={job_title}'
    # Send a GET request to the URL and parse the HTML content using BeautifulSoup
    response = requests.get(url)
    soup = BeautifulSoup(response.content, 'html.parser')
    # Find all job postings on the page
    job_list = soup.find_all('div', class_='vacancy-serp-item')
    # If no job postings were found, return None
    if not job_list:
        return None
    # Extract information about each job posting and store it in a dictionary
    jobs = []
    for job in job_list:
        job_title = job.find('a', class_='bloko-link HH-LinkModifier').text.strip()
        job_url = job.find('a', class_='bloko-link HH-LinkModifier')['href']
        job_location = job.find('span', class_='vacancy-serp-item__meta-info').text.strip()
        job_description = job.find('div', class_='g-user-content').text.strip()
        jobs.append({'title': job_title, 'url': job_url, 'location': job_location, 'description': job_description})
    # Return a list of dictionaries containing job posting information
    return jobs

# Function that sends job search results to a Telegram chat
def job_search(update, context):
    # Get the job title from the command arguments and search for job postings
    job_title = ' '.join(context.args)
    jobs = search_jobs(job_title)
    # If job postings were found, send a message with information about each posting
    if jobs:
        for job in jobs:
            message = f"{job['title']}\n{job['url']}\nLocation: {job['location']}\nDescription: {job['description']}"
            context.bot.send_message(chat_id=update.effective_chat.id, text=message)
    # If no job postings were found, send a message saying so
    else:
        context.bot.send_message(chat_id=update.effective_chat.id, text="No jobs found for this position")

# Replace 'TOKEN' with your own Telegram bot token
updater = telegram.ext.Updater('token')
# Add a command handler for the '/job' command that calls the job_search function
updater.dispatcher.add_handler(telegram.ext.CommandHandler('job', job_search))
# Start the bot's polling loop
updater.start_polling()
# Keep the bot running until it is stopped manually or by an error
updater.idle()

C:\Users\disas>python al.py
Traceback (most recent call last):
File "C:\Users\disas\al.py", line 1, in
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, ConversationHandler
ImportError: cannot import name 'Filters' from 'telegram.ext' (C:\Users\disas\AppData\Local\Programs\Python\Python311\Lib\site-packages\telegram\ext\__init__.py)


Пытался обновлять библиотку и заменять Filters на filters как сказано из одной статьи stackoverflow, но ошибка все равно остается.
  • Вопрос задан
  • 1401 просмотр
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы