0

I tried this code to scrape telegram's username, userids. I need to scrape user's about/bio info too but after trying many codes from telethon, pyrogram etc, it didnt't worked. I recently started learning python basics. I have mentioned below the code i have tried, but it didn't work. I am looking for scraping only userid, username and specially /about/bio info of group members.

Tried this code https://github.com/LonamiWebs/Telethon/issues/1243#issue-472897491

I did tried it by using below code but in out i am getting "function get_user_bio at 0x7f xxxxxxxxx" in place of bio in output, rest all details are coming perfectly, its just the bio information which is not correct.

from telethon.tl.functions.users
import GetFullUserRequest

async def get_user_bio(client, user):
    try:
    full_user = await client(GetFullUserRequest(user))
return full_user.full_user.about
except ChatAdminRequiredError:

# Get the user's bio
bio = full_user.full_user.about
Robert
  • 7,394
  • 40
  • 45
  • 64

1 Answers1

0

As you're already using, you'll need GetFullUserRequest to get the complete user.

The pitfall here is that GetFullUserRequest returns an object with the full_user attribute, so you'll need something like fullUser.full_user.about to get the Bio.


Consider this example were we

  1. Loop over each dialog we have iter_dialogs
  2. Loop over each member of this dialog iter_participants
  3. (Remember this in the seenUsers list so we're not going to call GetFullUserRequest for user's we've already checked)
  4. Get the complete user GetFullUserRequest
  5. Log about if it's set and not None
from telethon import TelegramClient
from telethon.tl.functions.users import GetFullUserRequest

import asyncio

async def main():

    seenUsers = []

    async with TelegramClient('anon', '111', '22') as client:

        # For each dialog
        async for dialog in client.iter_dialogs(limit = None):

            # For each particiipant
            async for user in client.iter_participants(entity=dialog, limit=None, aggressive=True):

                # Prevent double
                if user.first_name in seenUsers:
                    continue
                seenUsers.append(user.first_name)

                # Get full user
                fullUser = await client(GetFullUserRequest(user))

                # Log description
                if fullUser.full_user.about:

                    # Log
                    print(user.first_name + " has the following Bio:")
                    print(fullUser.full_user.about)

asyncio.run(main())

This will output something like:

Dirk has the following Bio:
Hi I'm Dirk

...
0stone0
  • 34,288
  • 4
  • 39
  • 64