-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Description
while True:
try:
# Отправляем GET-запрос на форум с заголовком User-Agent (имитация браузера)
headers = {"User-Agent": "Mozilla/5.0"}
r = requests.get(URL, headers=headers)
# Проверяем код ответа сервера
if r.status_code != 200:
print(f"Ошибка HTTP: {r.status_code}")
time.sleep(30) # Пауза при ошибке
continue # Переходим к следующей итерации цикла
# Парсим HTML-страницу
soup = BeautifulSoup(r.text, "html.parser")
thread = soup.select_one(".structItem-title a") # Находим первую тему (ссылку)
if thread: # Если тема найдена
title = thread.text.strip() # Извлекаем текст заголовка
href = thread["href"] # Извлекаем ссылку на тему
# Формируем полный URL
if href.startswith("http"):
link = href
else:
link = "https://forum.matrp.ru" + href
# Отправляем сообщение в Telegram, если заголовок изменился
if title != last_title:
last_title = title
message = f"🚨 Новая жалоба\n\n{title}\n{link}"
bot.send_message(chat_id=CHAT_ID, text=message)
print(f"[{time.strftime('%Y-%m-%d %H:%M:%S')}] Отправлена новость: {title}")
except Exception as e:
print(f"[{time.strftime('%Y-%m-%d %H:%M:%S')}] Ошибка: {e}")
time.sleep(30) # Пауза при исключении
time.sleep(60) # Пауза между проверками (60 секунд)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels