频道参与者对象不可订阅

发布于 2025-01-23 20:52:53 字数 1413 浏览 0 评论 0原文

具有“频道参与者”对象是Telethon中的可订阅错误。 我正在尝试从Telegram Group中将成员刮下到CSV文件。请帮忙!这是我的代码

for chat in chats:
    try:
        if chat.megagroup == True:
            groups.append(chat)
    except:
        continue
try:
    print('Choose a group to scrape members from:')
    i=0
    for g in groups:
        print(str(i) + '- ' + g.title)
        i+=1

    g_index = input("Enter a Number: ")
    target_group=groups[int(g_index)]


    print('Fetching Members...')
    all_participants = []
    all_participants = client.get_participants(target_group)
except TypeError:
    print("smth")
print('Saving In file...')
with open("members.csv","w",encoding='UTF-8') as f:
    writer = csv.writer(f,delimiter=",",lineterminator="\n")
    writer.writerow(['username','user id', 'access hash','name','group', 'group id'])
    for user in all_participants:
        if user.username:
            username= user.username
        else:
            username= ""
        if user.first_name:
            first_name= user.first_name
        else:
            first_name= ""
        if user.last_name:
            last_name= user.last_name
        else:
            last_name= ""
        name= (first_name + ' ' + last_name).strip()
        writer.writerow([username,user.id,user.access_hash,name,target_group.title, target_group.id])      
print('Members scraped successfully.')

在Google中找不到任何东西。与小组一起工作的一切。

Have "ChannelParticipants" object is not subscriptable error in telethon.
I am trying to scrape members to CSV file from telegram group. Please help! Here is my code

for chat in chats:
    try:
        if chat.megagroup == True:
            groups.append(chat)
    except:
        continue
try:
    print('Choose a group to scrape members from:')
    i=0
    for g in groups:
        print(str(i) + '- ' + g.title)
        i+=1

    g_index = input("Enter a Number: ")
    target_group=groups[int(g_index)]


    print('Fetching Members...')
    all_participants = []
    all_participants = client.get_participants(target_group)
except TypeError:
    print("smth")
print('Saving In file...')
with open("members.csv","w",encoding='UTF-8') as f:
    writer = csv.writer(f,delimiter=",",lineterminator="\n")
    writer.writerow(['username','user id', 'access hash','name','group', 'group id'])
    for user in all_participants:
        if user.username:
            username= user.username
        else:
            username= ""
        if user.first_name:
            first_name= user.first_name
        else:
            first_name= ""
        if user.last_name:
            last_name= user.last_name
        else:
            last_name= ""
        name= (first_name + ' ' + last_name).strip()
        writer.writerow([username,user.id,user.access_hash,name,target_group.title, target_group.id])      
print('Members scraped successfully.')

Can't find anything in google. Everything working with small groups.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戴着白色围巾的女孩 2025-01-30 20:52:53

尝试一下

      queryKey = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z','0','1','2','3','4','5','6','7','8','9',' ','','~', ':', "'", '+', '[', '\\', '@', '^', '{', '%', '(', '-', '"', '*', '|', ',', '&', '<', '`', '}', '.', '_', '=', ']', '!', '>', ';', '?', '#', '
, ')', '/']

      for key in queryKey:

          while True:
          participants = client(GetParticipantsRequest('channel/group_name', ChannelParticipantsSearch(key), 0, 200, 0))

          if not participants.users:
             break
          for users in participants.users:
             print(users)
         
          offset += len(participants.users)

Try this

      queryKey = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z','0','1','2','3','4','5','6','7','8','9',' ','','~', ':', "'", '+', '[', '\\', '@', '^', '{', '%', '(', '-', '"', '*', '|', ',', '&', '<', '`', '}', '.', '_', '=', ']', '!', '>', ';', '?', '#', '
, ')', '/']

      for key in queryKey:

          while True:
          participants = client(GetParticipantsRequest('channel/group_name', ChannelParticipantsSearch(key), 0, 200, 0))

          if not participants.users:
             break
          for users in participants.users:
             print(users)
         
          offset += len(participants.users)
终遇你 2025-01-30 20:52:53

设置限制对我工作的用户数量 -

await client.get_participants(group, aggressive=False, limit=2000)

您可以增加限制。

Setting limit to number of users worked for me-

await client.get_participants(group, aggressive=False, limit=2000)

You can increase the limit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文