首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何获取一个电报频道的(超过200个)成员列表

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

Stack Overflow用户
提问于 2019-01-08 23:44:58
回答 1查看 4.3K关注 0票数 3

好吧,让我们先说我是Python的菜鸟。因此,我正在与Telethon合作,以获得一个电报频道的全部(超过200个)成员列表。

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

代码语言:javascript
运行
复制
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()

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-08 23:54:55

你看过telethon文档了吗?它解释说,Telegram在服务器端有一个限制,只能收集一个组的前200名参与者。在我看来,您可以使用带有aggressive = Trueiter_participants函数来解决这个问题:

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

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

代码语言:javascript
运行
复制
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()
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54095191

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档