Created
July 3, 2023 19:32
-
-
Save medvedev/e48203ee314a0fc221e33c0f10dc341e to your computer and use it in GitHub Desktop.
Get all the URLs from a top (pinned) chat (channel) in Telegram
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from telethon.sync import TelegramClient | |
from telethon.tl.types import MessageMediaWebPage | |
# Can be optained at https://my.telegram.org/apps | |
api_id = <int value> | |
api_hash = <str value> | |
session_name = 'telegram_session' | |
def main(): | |
""" | |
Get all the URLs from the top-most chat in your account's chat list. In my case it was the 1st pinned channel. | |
""" | |
with TelegramClient(session_name, api_id, api_hash) as client: | |
client.start() | |
chat = next(client.iter_dialogs(limit=1)) | |
for message in client.iter_messages(chat, reverse=True): | |
if message.media is not None and isinstance(message.media, MessageMediaWebPage): | |
if message.media.webpage is not None: | |
print(message.media.webpage.url) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment