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
Try this
Setting limit to number of users worked for me-
You can increase the limit.