From 21f7b620ec4d89102912700be6fa41a8001a8692 Mon Sep 17 00:00:00 2001 From: Tristan Lee Date: Thu, 21 Apr 2022 18:26:31 -0500 Subject: [PATCH] moved forward finding out of tgme_widget_message_text clause, since it wasn't correctly getting the forwarding information in forwarded posts that contained attachments but no text --- snscrape/modules/telegram.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/snscrape/modules/telegram.py b/snscrape/modules/telegram.py index bed72cf..9cd7573 100644 --- a/snscrape/modules/telegram.py +++ b/snscrape/modules/telegram.py @@ -123,14 +123,13 @@ class TelegramChannelScraper(snscrape.base.Scraper): forwarded = None forwardedUrl = None + if (forward_tag := post.find('a', class_ = 'tgme_widget_message_forwarded_from_name')): + forwardedUrl = forward_tag['href'] + forwardedName = forwardedUrl.split('t.me/')[1].split('/')[0] + forwarded = Channel(username = forwardedName) + if (message := post.find('div', class_ = 'tgme_widget_message_text')): content = message.get_text(separator="\n") - - if (forward_tag := post.find('a', class_ = 'tgme_widget_message_forwarded_from_name')): - forwardedUrl = forward_tag['href'] - forwardedName = forwardedUrl.split('t.me/')[1].split('/')[0] - forwarded = Channel(username = forwardedName) - else: content = None