diff --git a/scraper.py b/scraper.py index 552e69b..463167d 100644 --- a/scraper.py +++ b/scraper.py @@ -64,40 +64,52 @@ def banner(): groups.append(chat) except: continue + +# To get input from user continuously we use this while loop +while(1): + print(gr+'[+] Choose a group to scrape members :'+re) + i=0 + for g in groups: + print(gr+'['+cy+str(i)+']' + ' - ' + g.title) + i+=1 + + # 'C' key to exit from I/O operation + print(gr+'[+] Press key C to exit') + print('') + g_index = input(gr+"[+] Enter a Number : "+re) + if(g_index=='C' or g_index=='c'): + break + target_group=groups[int(g_index)] -print(gr+'[+] Choose a group to scrape members :'+re) -i=0 -for g in groups: - print(gr+'['+cy+str(i)+']' + ' - ' + g.title) - i+=1 - -print('') -g_index = input(gr+"[+] Enter a Number : "+re) -target_group=groups[int(g_index)] - -print(gr+'[+] Fetching Members...') -time.sleep(1) -all_participants = [] -all_participants = client.get_participants(target_group, aggressive=True) + print(gr+'[+] Fetching Members...') + time.sleep(1) + all_participants = [] + all_participants = client.get_participants(target_group, aggressive=True) -print(gr+'[+] Saving In file...') -time.sleep(1) -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(gr+'[+] Members scraped successfully. Subscribe Termux Professor Youtube Channel For Add Members') + print(gr+'[+] Saving In file...') + time.sleep(1) + + if('members.csv' not in os.listdir()): + f=open('members.csv','w') + + #Appends data into a single csv file + if('members.csv' in os.listdir()): + with open("members.csv","a",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(gr+'[+] Members scraped successfully. Subscribe Termux Professor Youtube Channel For Add Members')