Ошибки TypeError: 'NoneType' object is not subscriptable в Телеграмм боте

Рейтинг: 0Ответов: 0Опубликовано: 21.05.2023

Я сейчас крайне жалею что выбрал такую тему для диплома, ибо мало чего понимаю в кодинге, но сделать бота нужно) Бот возвращает в канал команду старт и любое другое написанное сообщение, после чего крашится с вышеописанными ошибками

import telebot

import requests

import time

from bs4 import BeautifulSoup

token = ""
channel_id = ""
bot = telebot.TeleBot(token)

@bot.message_handler(content_types=['text'])
def commands(message):
    bot.send_message(channel_id, message.text)
    if message.text == "Старт":
        back_post_id = None
        while True:
            post_text = parser(back_post_id)
            back_post_id = post_text[1]

            if post_text[0] != None:
                bot.send_message(channel_id, post_text[0])
                time.sleep(1800)
    else:
        bot.send_message(message.from_user.id, "Я тебя не понимаю. Напиши Старт")

def parser(back_post_id):
    URL = "https://koopteh.onego.ru/news/allnews/"

    page = requests.get(URL)
    soup = BeautifulSoup(page.content, "html.parser")

    post = soup.find("div", class_="fullitem s1 clearfix", id=True)
    post_id = post["id"]
    
    if post_id != back_post_id:
        title = soup.find("div", class_="link-title").text.strip()
        description = soup.find("div", class_="notice").text.strip()
        
        return f"{title}\n\n{description}\n\n", post_id
    else:
        return None, post_id

bot.polling()

Ответы

Ответов пока нет.