-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScraper.py
More file actions
98 lines (78 loc) · 3.02 KB
/
Scraper.py
File metadata and controls
98 lines (78 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
print ("")
print ("++++++---++++++++++++---++++++++++++---++++++++++++---++++++++++++---++++++")
print ("+ ____ ____ _ _ _ + ")
print ("- / _| _ _ _ _ _ _ / _| |__ _ | | _| |_ _ - ")
print ("+ \_ \ / _ | '_ _ \ / _ \/ _ \ '__| | | | '_ \ / _ \| |/ / | | | + ")
print ("- _) | (_| | | | | | | / / | | |_| | | | (_) | <| | |_| | - ")
print ("+ |____/ \__,_|_| |_| |_|\___|\___|_| \____|_| |_|\___/|_|\_\_|\__, | + ")
print ("- |___/ - ")
print ("++++++---++++++++++++---++++++++++++---++++++++++++---++++++++++++---++++++")
print ("")
from telethon.sync import TelegramClient
from telethon.tl.functions.messages import GetDialogsRequest
from telethon.tl.types import InputPeerEmpty
import csv
api_id = 2547332 #Enter Your 7 Digit Telegram API ID.
api_hash = '3c5bae86e2e0bbc402559ec8b20ba0c0' #Enter Yor 32 Character API Hash
phone = '+917755818339 ' #Enter Your Mobilr Number With Country Code.
client = TelegramClient(phone, api_id, api_hash)
async def main():
# Now you can use all client methods listed below, like for example...
await client.send_message('me', 'Hello !!!!')
with client:
client.loop.run_until_complete(main())
client.connect()
if not client.is_user_authorized():
client.send_code_request(phone)
client.sign_in(phone, input('Enter verification code: '))
chats = []
last_date = None
chunk_size = 200
groups=[]
result = client(GetDialogsRequest(
offset_date=last_date,
offset_id=0,
offset_peer=InputPeerEmpty(),
limit=chunk_size,
hash = 0
))
chats.extend(result.chats)
for chat in chats:
try:
if chat.megagroup== True:
groups.append(chat)
except:
continue
print('From Which Group Yow Want To Scrap A Members:')
i=0
for g in groups:
print(str(i) + '- ' + g.title)
i+=1
g_index = input("Please! Enter a Number: ")
target_group=groups[int(g_index)]
print('Fetching Members...')
all_participants = []
all_participants = client.get_participants(target_group, aggressive=True)
print('Saving In file...')
with open("Scrapped.csv","w",encoding='UTF-8') as f:#Enter your file name.
writer = csv.writer(f,delimiter=",",lineterminator="\n")
writer.writerow(['username','user id', 'access hash','name','group', 'group id'])
number = 1
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()
if(username!=""):
writer.writerow([username, user.id, user.access_hash, name, target_group.title, target_group.id])
print('Members scraped successfully.......')
print('Happy Hacking......')