Telegram Scraper 2022 - Scrape Telegram Group and Channels
Scrolling down in a Telegram group's members' list and copy pasting every username is a tedious
and time-consuming process. Here is where programming comes in! Making tedious and time-consuming jobs easy and enjoyable!
There are two ways to:
scrape telegram group members
1. Use Telegram Group Crawler which is a great scrape telegram channel and group tool.
2. Do the code yourself! which I explain in details below!
First of all you will need to install python on your operating system. After that, assuming you have a working python installation, you will need to install
telethonwhich is a python client for Telegram API.
pip install telethon
Then in any text editor that you prefer type in
from telethon import TelegramClient, sync
This will import the
TelegramClientobject that gonna be used for connecting to the Telegram API. the
syncindicates that we want a sync (and not async!) functionality of the library. The next step is obtaining
API_HASHfrom Telegram Account Management Dashboard.
client = TelegramClient(SessionName, API_ID, API_HASH)
SessionNameis the session you want to use for connecting to the Telegram API. The next step is to connect to the Telegram API.
thats all! Next we need to target the group that we want to take members from.
get_entityis the method we use for such purpose. We will use EliteCryptoForex as sample for this tutorial.
group = client.get_entity('https://t.me/EliteCryptoForex')
The next step is to join the group. So we import
from telethon.tl.functions.channels import JoinChannelRequest
and in the next line
Next we ask Telegram API to give us the participates list of this group. easy huh?
participants = client.get_participants(group)
Now we iterate through participants and write their usernames (each one in a new line!) to a file!
with open('members.txt', 'a') as members:
for p in participants:
Contact me directly if you have any questions regarding the script! Please note that you can only scrape channels that you are an admin of. But you can scrape any groups you want. You could also buy Telegram Group Scraper or Buy Telegram Members using other sections of the website.
Author: Amin Etesamian