蟒蛇。从.txt文件中删除单词

时间:2018-08-19 03:21:15

标签: python

我正在使用此代码从Telegram组获取所有用户

while True:
    participants = client(GetParticipantsRequest(
        channel, ChannelParticipantsSearch(''), offset, limit, hash=0
    ))
    if not participants.users:
        break
    all_participants.extend(participants.users)
    offset += len(participants.users)
    print(offset)
    print(all_participants)

输出的格式为-[<telethon.tl.types.User object at 0x03AFB3D0>]

然后:

thefile = open('file.txt', 'w')

#for participant in all_participants:
    #thefile.write("%s\n" % participant)

    #print(all_participants)

我的文件现在有很多行,其中包含很多信息(我删除了很多内容,以免显得混乱)

User(is_self=False, contact=False,, first_name='NAME', last_name=NAME, username='HIS_USERNAME')

如何删除所有内容,而仅在文件中包含HIS_USERNAME? 因此,我只希望拥有用户名,而不是具有完整信息的行。

我知道最好的方法是使用Telegram API,但我还没有找到仅获取用户名的方法。

0 个答案:

没有答案
相关问题