3

好的,让我们首先说我是一个 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()

有人有解决方案吗?谢谢!!

4

1 回答 1

3

你看过电视马拉松的文档吗?它解释说,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()
于 2019-01-08T15:54:54.863 回答