import requests import re import html urls = { "codinglove": "https://thecodinglove.com/", "wikihow": "https://de.wikihow.com/Spezial:Randomizer" } def send_coding_love_gif(bot, update): random_url = re.search('href="(.*)".*\n.*\n.*random\( \)', requests.get(urls["codinglove"]).text).group(1) random_page_content = requests.get(random_url) random_page_content.encoding = 'utf-8' random_page_content = html.unescape(random_page_content.text) caption = re.search('blog-post-title">(.*)', random_page_content).group(1) gif_match = re.search('data="(.*)" type="image/gif"', random_page_content) if gif_match is None: gif_match = re.search('og:image" content="(.*)"', random_page_content) if gif_match: gif_url = gif_match.group(1) bot.send_animation(chat_id=update.message.chat_id, animation=gif_url, caption=caption) else: update.message.reply_text("Error fetching image: %s ¯\_(ツ)_/¯" % random_url) def send_wiki_how_article(bot, update): random_howto = requests.get(urls["wikihow"]) howto_title = re.search('