好吧,让我们先说我是一个 Python 菜鸟。 因此,我正在使用 Telethon 获取 Telegram channel 的完整(超过 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
来颠覆这个问题:
我以前没有用过这个包,但看起来你可以这样做:
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()
关于python - 如何获取 Telegram channel (超过 200 个)成员的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54095191/