skip to Main Content

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.

2

Answers


  1. 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)
    
    Login or Signup to reply.
  2. Setting limit to number of users worked for me-

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

    You can increase the limit.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search