I did bot in a telegram to the sending of news from a particular site.
When you turn on the parser itself without the bot, it displays all the information from news feeds to the console, but when I turn the bot write command at Tg for information, it sends only one news. Fix my code and make it so he sent 5 or 10 news from the tape instead of one.
from bs4 import BeautifulSoup
import requests
import telebot
bot = telebot.TeleBot('config.token')
url = 'http://mignews.com/mobile'
page = requests.get(url)
new_news = []
soup = BeautifulSoup(page.text, "html.parser")
news = soup.findAll('a', class_='lenta')
for i in range(len(news)):
if news[i].find('span', class_='time2 time3') is not None:
new_news.append(news[i].text)
for i in range(len(new_news)):
@bot.message_handler(commands=['start'])
def start_message(message):
bot.send_message(message.chat.id, 'Hello, you wrote me /start')
@bot.message_handler(content_types=['text'])
def send_text(message):
if message.text == 'news':
bot.send_message(message.chat.id new_news[:5])
elif message.text == 'News':
bot.send_message(message.chat.id new_news[:5])
bot.polling()
bot.send_message(message.chat.id, ' '.join(new_news[:5]))
Ahem... I do not understand to be honest - elmira18 commented on April 19th 20 at 12:34