我想创建一个 Telegram 机器人来检查网站上是否有新帖子(目前出于测试目的每 15 秒检查一次)。如果是这样,它应该将包含帖子内容的消息发送到 Telegram 频道。
为此,我已经有了以下“代码骨架”:(格式化和添加方面的精细工作稍后进行)
import requests
import asyncio
from bs4 import BeautifulSoup
from telegram import InputMediaPhoto
from telegram.ext import Updater
# Telegram Bot API Token
API_TOKEN = 'XXXXXXXXXXXXXXXXX'
# URL of the website
URL = 'https://chemiehalle.de'
# List for storing seen posts
seen_posts = []
# Function for fetching posts
def get_posts():
# Send request to the website
res = requests.get(URL)
# Parse HTML content
soup = BeautifulSoup(res.content, 'html.parser')
# Find all posts on the website …Run Code Online (Sandbox Code Playgroud)