好吧,让我们先说我是Python的菜鸟。因此,我正在与Telethon合作,以获得一个电报频道的全部(超过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()
有人有解决方案吗?谢谢!!
发布于 2019-01-08 23:54:55
你看过telethon文档了吗?它解释说,Telegram在服务器端有一个限制,只能收集一个组的前200名参与者。在我看来,您可以使用带有aggressive = True
的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()
https://stackoverflow.com/questions/54095191
复制相似问题