Files
SoftwareManager/core/data/scrapers/monkrus.py
T
2025-10-18 01:33:12 +02:00

29 lines
877 B
Python

from core.utils.data.state import state
from bs4 import BeautifulSoup
import requests
def scrape_monkrus_telegram():
telegram_channel = "https://t.me/s/real_monkrus/"
posts: list[dict] = []
response = requests.get(telegram_channel)
soup = BeautifulSoup(response.text, "html.parser")
bubbles = soup.find_all("div", class_="tgme_widget_message_bubble")
for bubble in bubbles:
post_txt = bubble.find("div", class_="tgme_widget_message_text js-message_text")
title = post_txt.b.text
url = bubble.find("a", href=lambda x: x and x.startswith("https://uztracker.net"))
posts.append(dict(
author = "m0nkrus",
id = len(posts) + 1,
title = title,
url = url["href"]
))
posts.reverse() # reverse to show most recent posts (bubbles) at top of list
return(posts)