Python Forum
Telegram Users Scrapper - Exclude UserPrivacyRestricted
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Telegram Users Scrapper - Exclude UserPrivacyRestricted
#1
Hi expert coders,
I am using following python script to export Telegram Group users in .csv format.
It is exporting a csv file from the targeted public group. In the csv file I am getting Privacy Restricted users also. Can someone alter this code to export without PrivacyRestricted users?

Thanks in advance.

import csv
import configparser
import traceback

from telethon.sync import TelegramClient
from telethon import types, utils, errors
from telethon.tl.functions import channels
from add import read_csv, write_csv


try:
    config = configparser.ConfigParser()
    config.read("config.ini")

    channel = config['Telegram']['from_channel']
    phone = utils.parse_phone(config['Telegram']['main_phone'])
    api = read_csv('api.csv')[0]


    client = TelegramClient(f"sessions/{phone}", *api)
    client.start(phone)


    rows = [
        ['ID', 'Name', 'Username', 'Phone']
    ]

    print("Getting participants...")

    for participant in client.iter_participants(channel, aggressive=True):
        print(f"Got {len(rows)}", end='\r')
        rows.append([
            participant.id,
            utils.get_display_name(participant),
            participant.username,
            participant.phone
        ])


    print("\nWriting output")
    write_csv('users.csv', rows)
    print("Done!")


finally:
    input()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Regex Include and Exclude patterns in Same Expression starzar 2 784 May-23-2023, 09:12 AM
Last Post: Gribouillis
  [SOLVED] [loop] Exclude ranges in… range? Winfried 2 1,438 May-14-2023, 04:29 PM
Last Post: Winfried
  Telegram bot python help! wolfdevs 0 770 Sep-07-2022, 11:34 AM
Last Post: wolfdevs
  Bot coding telegram.ext Kumarkv 1 1,866 May-29-2020, 01:00 AM
Last Post: Kumarkv
  How to exclude bools from integers? boris602 2 1,955 Nov-02-2019, 12:44 PM
Last Post: boris602
  loop through range until reach size and exclude specific symbol pino88 3 2,369 Sep-23-2019, 02:32 AM
Last Post: perfringo
  List Comprehension to exclude first row tkj80 5 4,930 Jun-11-2018, 09:24 AM
Last Post: volcano63
  Exclude words with specific endings from list Epileptiker 5 4,210 Apr-06-2018, 02:40 PM
Last Post: nilamo
  Question about telegram bot Romank 0 2,243 Mar-29-2018, 09:36 PM
Last Post: Romank
  Telegram code help AaronJonk 0 9,497 Oct-05-2017, 02:44 PM
Last Post: AaronJonk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020