Python:
import requests
from bs4 import BeautifulSoup
import random
import logging
from aiogram import Bot, Dispatcher, types, executor
bot = Bot(token='your_token_here')
dp = Dispatcher(bot)
logging.basicConfig(level=logging.INFO)
url = 'http://anekdotme.ru/random'
def get_random_joke():
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
jokes_list = soup.find_all('div', class_='anekdot_text')
random_joke = random.choice(jokes_list)
return random_joke.text.strip()
@dp.message_handler(commands=['start'])
async def start_handler(message: types.Message):
logging.info(f"User {message.from_user.id} requested a joke")
joke = get_random_joke()
await message.answer(joke)
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)