如何获取电报频道(超过 200 个)成员的列表

How to get the list of (more than 200) members of a Telegram channel

好吧,让我们先说我是一个 Python 完全菜鸟。 因此,我正在使用 Telethon 获取 Telegram 频道的完整(超过 200 个)成员列表。

反复尝试,我发现这段代码完美地达到了我的目标,如果不是它只打印前 200 个成员的话。

from telethon import TelegramClient, sync

# Use your own values here
api_id = xxx
api_hash = 'xxx'
name = 'xxx'
channel = 'xxx'

client = TelegramClient('Lista_Membri2', api_id, api_hash)
try:
client.start()  
# get all the channels that I can access
channels = {d.entity.username: d.entity
        for d in client.get_dialogs()
        if d.is_channel}

# choose the one that I want list users from
channel = channels[channel]

# get all the users and print them
for u in client.get_participants(channel):
 print(u.id, u.first_name, u.last_name, u.username)

#fino a qui il codice

finally:
client.disconnect()

有人有解决办法吗? 谢谢!!

你看过电视节目的文档了吗?它解释说 Telegram 有一个服务器端限制,只能收集一个组的前 200 名参与者。据我所知,您可以使用 iter_participants 函数和 aggressive = True 来颠覆这个问题:

https://telethon.readthedocs.io/en/latest/telethon.client.html?highlight=200#telethon.client.chats.ChatMethods.iter_participants

我以前没有用过这个包,但看起来你可以这样做:

from telethon import TelegramClient

# Use your own values here
api_id = 'xxx'
api_hash = 'xxx'
name = 'xxx'
channel = 'xxx'

client = TelegramClient('Lista_Membri2', api_id, api_hash)

client.start()  
# get all the channels that I can access
channels = {d.entity.username: d.entity
            for d in client.get_dialogs()
            if d.is_channel}

# choose the one that I want list users from
channel = channels[channel]

# get all the users and print them
for u in client.iter_participants(channel, aggressive=True):
  print(u.id, u.first_name, u.last_name, u.username)

#fino a qui il codice
client.disconnect()