-
Notifications
You must be signed in to change notification settings - Fork 1
/
inScrape.py
4752 lines (4337 loc) · 270 KB
/
inScrape.py
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from selenium import webdriver
import time
import os
import requests
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
# By Amr Elkhamisy
# This is a script to scrape your data from Instagram or Facbook, it's a simple script that uses selenium to scrape data from
print("1-Instagram 2-Facebook")
rte = input("Choose 1 or 2: ")
if "1" in str(rte):
headss = ["Phone", "Name", "User Name", "Actual Bio", "Email", "Gender", "Website",
"Contact Names", "Contact Numbers", "Follow Requests", "Login Activities",
"Search History", "Followers", "Following", "Bios", "Blocked", "Ads Interests",
"Emails Sent", "Login", "Logout", "Password Changes",
"Date Joined", "Date of Birth", "Date Upgraded", "Former Usernames", "Formers Gmails",
"Story Poll Votes", "Hashtags you follow", "Former Phones", "Story Bookmarked Music",
"Former full names", "Former links in bio", "Story emoji slider votes",
"story question responses", "story countdown follows",
"story quiz responses", "Account privacy changes", "Apps and Websites", "Emails Sent Others",
"accounts you hide stories from", "Photos"]
kilo = 0
# Filtered Topics
heads = []
# Showing topics info var to choose
info = "Choose From: "
for sf in headss:
info += str(kilo) + "- " + sf + " "
kilo += 1
print(info)
# If it's all, will get all variables, if it's numbers seperated with commas will filter them
headss_num = input("Choosed Ones (1,6 for example) or type all: ")
if "all" in headss_num:
heads = headss
else:
for poto in headss_num.split(","):
print(poto)
heads.append(headss[int(poto)])
print(heads)
# Opening the window
driver = webdriver.Chrome()
password_changes = []
# Asking For email, and password
email = input("Email or Username: ")
password = input("Password: ")
# Defining Variables
phone = ""
name = ""
user_name = ""
actual_bio = ""
email_of_mine = ""
gender = ""
date_joined = ""
data_of_birth = ""
date_upgraded = ""
contact_names = []
contact_numbers = []
follow_requests = []
logins = []
search_history = []
followers = []
following = []
story_poll_votes = []
story_emoji_slider_votes = []
story_question_responses = []
story_countdown_follows = []
story_quiz_responses = []
hashtags_you_follow = []
former_phones = []
manage_access = []
story_bookmarked_music = []
accounts_you_hide_stories_from = []
former_full_names = []
former_links_in_bio = []
account_privacy_changes = []
logouts_date = []
website = ""
emails = []
former_usernames = []
bios = []
emails_others = []
blocked = []
logins_date = []
former_emails = []
ads_interests = []
photos = []
row = 1
if __name__ == '__main__':
# Variables used:
# z for list locating
# as you see each date in a new list there
# p for list switching
# and ws for scrolling
driver.get("https://www.instagram.com/accounts/login/")
# Time wait (To avoid element not found error)
time.sleep(10)
# Adding username and password
driver.find_element(By.NAME, "username").send_keys(email)
driver.find_element(By.NAME, "password").send_keys(password)
# Clicking on login button
driver.find_element(By.CSS_SELECTOR, ".L3NKy").click()
time.sleep(10)
for fik in heads:
# Check if one of wanted data from about overview data
if fik in str(["Phone", "Name", "User Name", "Actual Bio", "Email", "Gender", "Website"]):
driver.get("https://www.instagram.com/accounts/edit/")
time.sleep(2)
# Get info in https://www.instagram.com/accounts/edit/
if fik == "Name":
name += str(driver.find_element_by_id("pepName").get_attribute("value"))
if fik == "User Name":
user_name += str(driver.find_element_by_id("pepUsername").get_attribute("value"))
if fik in "Phone":
phone += str(driver.find_element_by_id("pepPhone Number").get_attribute("value"))
if fik in "Email":
email_of_mine += str(driver.find_element_by_id("pepEmail").get_attribute("value"))
if fik in "Website":
website += str(driver.find_element_by_id("pepWebsite").get_attribute("value"))
if fik in "Actual Bio":
actual_bio += str(driver.find_element_by_id("pepBio").text)
if fik in "Gender":
gender += str(driver.find_element_by_id("pepGender").get_attribute("value"))
if fik in str(["Date Joined", "Date of Birth", "Date Upgraded"]):
# Time Delay to be more realistic (avoiding ban) and to ensure site load
time.sleep(3)
driver.get("https://www.instagram.com/accounts/access_tool/")
if fik in "Date Joined":
date_joined = str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/div/div[1]/section[1]/section[1]/div").text)
if fik in "Date of Birth":
data_of_birth = str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/div/div[1]/section[1]/section[6]/div").text)
if fik in "Date Upgraded":
date_upgraded = str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/div/div[1]/section[1]/section[7]/div").text)
if fik in ["Contact Names", "Contact Numbers"]:
z = 1
# Opening Contact History
driver.get("https://www.instagram.com/accounts/contact_history/")
time.sleep(3)
while True:
try:
# Getting Contact History and Add it in a List
if fik in "Contact Names":
contact_names.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/div[1]/div[5]/div[" + str(
z) + "]/div/div[1]/h1").text))
if fik in "Contact Numbers":
contact_numbers.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/div[1]/div[5]/div[" + str(
z) + "]/div/div[2]/h1").text))
z += 1
except:
break
print(contact_numbers)
print(contact_names)
if fik in "Login Activities":
z = 2
driver.get("https://www.instagram.com/session/login_activity/")
# Time Delay to be more realistic (avoiding ban) and to ensure site load
time.sleep(3)
while True:
try:
# Getting Login-s and Add it in a List
logi = ""
logi += str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/div/div[2]/div[3]/div[" + str(
z) + "]/div/div/div[2]/div[1]/div/div").text).replace("\xa0·\xa0", " ").replace(",",
"") + " "
logi += str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/div/div[2]/div[3]/div[" + str(
z) + "]/div/div/div[2]/div[2]/div/div").get_attribute("innerText")).replace(
"\xa0·\xa0", " ")
logins.append(logi)
z += 2
except:
break
print(logins)
if fik in "Follow Requests":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/current_follow_requests")
# Time Delay to be more realistic (avoiding ban) and to ensure site load
time.sleep(3)
while True:
try:
# Getting Follow Requests and Add it in a List
follow_requests.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(z) + "]").text))
z += 1
except:
break
if fik in "Blocked":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/accounts_you_blocked")
# Time Delay to be more realistic (avoiding ban) and to ensure site load
time.sleep(3)
while True:
try:
# Getting Blocked Accounts and Add it in a List
blocked.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(z) + "]").text))
z += 1
except:
break
if fik in "Search History":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/search_history")
# Time Delay to be more realistic (avoiding ban) and to ensure site load
time.sleep(3)
while True:
try:
# Getting Search History and Add it in a List
search_history.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(z) + "]").text))
z += 1
except:
break
if fik in "Bios":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/former_bio_texts")
# Time Delay to be more realistic (avoiding ban) and to ensure site load
time.sleep(3)
while True:
try:
# Getting Bios since account opened and Add it in a List
bios.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(z) + "]").text))
z += 1
except:
break
if fik in "Ads Interests":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/ads_interests")
# Time Delay to be more realistic (avoiding ban) and to ensure site load
time.sleep(3)
while True:
try:
# Getting Ads Interests and Add it in a List
ads_interests.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(z) + "]").text))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in "Followers":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/accounts_following_you")
# Time Delay to be more realistic (avoiding ban) and to ensure site load
time.sleep(3)
while True:
try:
# Getting Followers and Add it in a List
followers.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(z) + "]").text))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in "Following":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/accounts_you_follow")
# Time Delay to be more realistic (avoiding ban) and to ensure site load
time.sleep(3)
while True:
try:
# Getting Following and Add it in a List
following.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(z) + "]").text))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in ["Emails Sent", "Emails Sent Others"]:
z = 2
driver.get("https://www.instagram.com/emails/emails_sent/")
# Time Delay to be more realistic (avoiding ban) and to ensure site load
time.sleep(2)
while True:
try:
try:
# Getting Emails Sent and Add it in a List
if fik == "Emails Sent":
emeil = ""
emeil += str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/div/div[2]/div[2]/div[" + str(
z) + "]/div[2]").text) + " "
emails.append(emeil.replace("\\n", ", ").replace(r"\n", ", ").replace("\n", ", "))
z += 1
else:
raise StopIteration
except:
if fik == "Emails Sent Others":
z = 2
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/div/div[2]/div[1]/a[2]").click()
time.sleep(2)
while True:
try:
emeil = ""
emeil += str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/div/div[2]/div[2]/div[" + str(
z) + "]/div[2]").text).replace(",", " ")
emails_others.append(emeil.replace("\\n", ", ").replace(r"\n", ", ").replace("\n", ", "))
z += 1
except:
raise StopIteration
else:
raise StopIteration
except StopIteration:
break
if fik in "Login":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/logins")
# Time Delay to be more realistic (avoiding ban) and to ensure site load
time.sleep(2)
while True:
try:
# Getting logins_date and Add it in a List
logins_date.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(
z) + "]").text).replace(", ", " "))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in "Logout":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/logouts")
# Time Delay to be more realistic (avoiding ban) and to ensure site load
time.sleep(2)
while True:
try:
# Getting logouts_date and Add it in a List
logouts_date.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(
z) + "]").text).replace(", ", " "))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in "Password Changes":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/password_changes")
time.sleep(2)
# Time Delay to be more realistic (avoiding ban) and to ensure site load
while True:
try:
# Getting Password Changes and Add it in a List
password_changes.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(
z) + "]").text).replace(", ", " "))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in "Former Usernames":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/former_usernames")
time.sleep(2)
# Time Delay to be more realistic (avoiding ban) and to ensure site load
while True:
try:
# Getting Former Usernames and Add it in a List
former_usernames.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(z) + "]").text))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in "Formers Gmails":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/former_emails")
time.sleep(2)
# Time Delay to be more realistic (avoiding ban) and to ensure site load
while True:
try:
# Getting Formers Gmails and Add it in a List
former_emails.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(z) + "]").text))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in "Hashtags you follow":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/hashtags_you_follow")
time.sleep(2)
# Time Delay to be more realistic (avoiding ban) and to ensure site load
while True:
try:
# Getting Hashtags you follow and Add it in a List
hashtags_you_follow.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(z) + "]").text))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in "Former Phones":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/former_phones")
time.sleep(2)
# Time Delay to be more realistic (avoiding ban) and to ensure site load
while True:
try:
# Getting Former Phones and Add it in a List
former_phones.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(z) + "]").text))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in "Story Poll Votes":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/story_poll_votes")
time.sleep(2)
# Time Delay to be more realistic (avoiding ban) and to ensure site load
while True:
try:
# Getting Story Poll Votes and Add it in a List
story_poll_votes.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(
z) + "]").text).replace(", ", " "))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in "Story emoji slider votes":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/story_emoji_slider_votes")
time.sleep(2)
# Time Delay to be more realistic (avoiding ban) and to ensure site load
while True:
try:
# Getting Story emoji slider votes and Add it in a List
story_emoji_slider_votes.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(
z) + "]").text).replace(", ", " "))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in "story question responses":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/story_question_responses")
time.sleep(2)
# Time Delay to be more realistic (avoiding ban) and to ensure site load
while True:
try:
# Getting story question responses and Add it in a List
story_question_responses.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(
z) + "]").text).replace(", ", " "))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in "story countdown follows":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/story_countdown_follows")
time.sleep(2)
# Time Delay to be more realistic (avoiding ban) and to ensure site load
while True:
try:
# Getting story countdown follows and Add it in a List
story_countdown_follows.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(
z) + "]").text).replace(", ", " "))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in "Story Bookmarked Music":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/story_bookmarked_music")
time.sleep(2)
# Time Delay to be more realistic (avoiding ban) and to ensure site load
while True:
try:
# Getting Story Bookmarked Music and Add it in a List
story_bookmarked_music.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(
z) + "]").text).replace(", ", " "))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in "story quiz responses":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/story_quiz_responses")
time.sleep(2)
# Time Delay to be more realistic (avoiding ban) and to ensure site load
while True:
try:
# Getting story quiz responses and Add it in a List
story_quiz_responses.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(
z) + "]").text).replace(", ", " "))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in "Former links in bio":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/former_links_in_bio")
time.sleep(2)
# Time Delay to be more realistic (avoiding ban) and to ensure site load
while True:
try:
# Getting Former links in bio and Add it in a List
former_links_in_bio.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(
z) + "]").text).replace(", ", " "))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in "Former full names":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/former_full_names")
time.sleep(2)
# Time Delay to be more realistic (avoiding ban) and to ensure site load
while True:
try:
# Getting Former full names and Add it in a List
former_full_names.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(
z) + "]").text).replace(", ", " "))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in "accounts you hide stories from":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/accounts_you_hide_stories_from")
time.sleep(2)
# Time Delay to be more realistic (avoiding ban) and to ensure site load
while True:
try:
# Getting accounts you hide stories from and Add it in a List
accounts_you_hide_stories_from.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(
z) + "]").text).replace(", ", " "))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in "Account privacy changes":
z = 1
driver.get("https://www.instagram.com/accounts/access_tool/account_privacy_changes")
time.sleep(2)
# Time Delay to be more realistic (avoiding ban) and to ensure site load
while True:
try:
# Getting Account privacy changes and Add it in a List
account_privacy_changes.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(
z) + "]").text).replace(", ", " "))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
if fik in "Apps and Websites":
z = 1
driver.get("https://www.instagram.com/accounts/manage_access/")
time.sleep(2)
# Time Delay to be more realistic (avoiding ban) and to ensure site load
while True:
try:
# Getting Apps and Websites and Add it in a List
manage_access.append(str(driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/section/div[" + str(
z) + "]").text).replace(", ", " "))
z += 1
except:
try:
# Clicking on view more button to get more for the list
driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/article/main/button").click()
time.sleep(2)
continue
except:
break
# Check If data is of Photos, if so, will get the username to get to profile, then get all images of the
# User, then download it.
if fik == "Photos":
t = 0
driver.get("https://www.instagram.com/accounts/edit/")
time.sleep(2)
user = str(driver.find_element_by_id("pepUsername").get_attribute("value"))
while True:
driver.get("https://www.instagram.com/" + user)
try:
driver.find_elements_by_class_name("_9AhH0")[t].click()
time.sleep(3)
try:
imgs = driver.find_elements_by_class_name("FFVAD")[len(driver.find_elements_by_class_name("FFVAD"))-1]
photos.append(imgs.get_attribute("src"))
except:
pass
t += 1
except:
break
image = 1
for ifa in photos:
try:
img_data = requests.get(ifa).content
with open('image' + str(image) + '.jpg', 'wb') as handler:
handler.write(img_data)
print("Image " + str(image) + " Downloaded")
image += 1
except Exception as e:
print(e)
pass
# Adding data to a data frame
datas_to_scrape = [phone, name, user_name, actual_bio,
email_of_mine, gender, website,
str(contact_names).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
str(contact_numbers).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
str(follow_requests).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
str(logins).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
str(search_history).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
str(followers).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
str(following).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
str(bios).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
str(blocked).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
str(ads_interests).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
str(emails).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
str(logins_date).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
str(logouts_date).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
str(password_changes).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
date_joined, data_of_birth, date_upgraded,
str(former_usernames).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
str(former_emails).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
str(story_poll_votes).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
str(hashtags_you_follow).replace("[", "").replace("]", "").replace("'", "").replace(", ",
"\n"),
str(former_phones).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
str(story_bookmarked_music).replace("[", "").replace("]", "").replace("'", "").replace(", ",
"\n"),
str(former_full_names).replace("[", "").replace("]", "").replace("'", "").replace(", ",
"\n"),
str(former_links_in_bio).replace("[", "").replace("]", "").replace("'", "").replace(", ",
"\n"),
str(story_emoji_slider_votes).replace("[", "").replace("]", "").replace("'", "").replace(
", ",
"\n"),
str(story_question_responses).replace("[", "").replace("]", "").replace("'", "").replace(
", ",
"\n"),
str(story_countdown_follows).replace("[", "").replace("]", "").replace("'", "").replace(", ",
"\n"),
str(story_quiz_responses).replace("[", "").replace("]", "").replace("'", "").replace(", ",
"\n"),
str(account_privacy_changes).replace("[", "").replace("]", "").replace("'", "").replace(", ",
"\n"),
str(manage_access).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
str(emails_others).replace("[", "").replace("]", "").replace("'", "").replace(", ", "\n"),
str(accounts_you_hide_stories_from).replace("[", "").replace("]", "").replace("'",
"").replace(
", ", "\n"),
str(photos).replace("[", "").replace("]", "").replace("'",
"").replace(
", ", "\n")]
print(len(datas_to_scrape))
# List of filtered data
datas_to_scrape_filtered = []
# if all get all datas_to_scrape that contains all possible
if "all" in headss_num:
datas_to_scrape_filtered = datas_to_scrape
else:
# filter unwanted data and add wanted ones
for poto in headss_num.split(","):
print(poto)
datas_to_scrape_filtered.append(datas_to_scrape[int(poto)])
# put results in results.txt file
heads_num = 0
results = open("results_instagram.txt", "w+", encoding="utf8")
print(datas_to_scrape_filtered)
for data in datas_to_scrape_filtered:
print(heads, heads_num)
results.write("\n\n\n\n########## " + str(heads[heads_num]) + " ##########\n\n")
results.write(str(data) + "\n")
heads_num += 1
results.close()
driver.close()
else:
# All Topics To Scrape
headss = ["Name", "Job", "Education", "Living in", "From", "Relationship", "Mobile", "search", "LIKEDPOSTS",
"REMOVEDFRIENDS", "FRIENDS", "SENTFRIENDREQUESTS", "RECEIVEDFRIENDREQUESTS", "interests",
"TAGSBYOTHERSCLUSTER", "WALLCLUSTER", "HIDDENSTORIES", "LIKEDINTERESTS", "following", "LOGINSLOGOUTS",
"ACTIVESESSIONS", "COMMENTSCLUSTER", "VIDEOWATCH", "GROUPMEMBERSHIP", "STATUSCLUSTER",
"ARCHIVED", "QUESTIONSCLUSTER", "saved", "saved link", "CREATEDEVENTS", "EVENTRSVPS", "INVITEDEVENTS",
"MARKETPLACESELLERRESPONSES", "GROUPPOSTS", "CHANGECONTEXTUALPROFILE", "ARCHIVEDSTORIES",
"NOTECLUSTER", "VIDEOPOLLSVOTED", "YOURPLACES", "VIDEO_SEARCH", "VOICESEARCH",
"PRIVACYCHECKUPINTERACTION",
"PRIVACYCHECKUPREMINDER", "RECOGNIZEDDEVICES", "ALLAPPS", "YOURTIMELINEPOSTS",
"TAGGEDPHOTOS", "TRASH", "primary_location", "Photos", "personal_info_grouping", "Messenger",
"about_places", "about_contact_and_basic_info", "FRIENDS_PHOTOS", "about_family_and_relationships",
"about_life_events", "about_details", "about_work_and_education"]
kilo = 0
# Filtered Topics
heads = []
# Showing topics info var to choose
info = "Choose From: "
for sf in headss:
info += str(kilo) + "- " + sf + " "
kilo += 1
print(info)
# If it's all, will get all variables, if it's numbers seperated with commas will filter them
headss_num = input("Choosed Ones (1,6 for example) or type all: ")
if "all" in headss_num:
heads = headss
else:
for poto in headss_num.split(","):
print(poto)
heads.append(headss[int(poto)])
print(heads)
# Login Details
dri = webdriver.Chrome()
dri.maximize_window()
email = input("Email: ")
password = input("Password: ")
list1 = []
list2 = []
list3 = []
list4 = []
list5 = []
list6 = []
list7 = []
list8 = []
list9 = []
list10 = []
list11 = []
list12 = []
list13 = []
list14 = []
list15 = []
list16 = []
list17 = []
list18 = []
list19 = []
list20 = []
list21 = []
list22 = []
list23 = []
list24 = []
list25 = []
list26 = []
list27 = []
list28 = []
list29 = []
list30 = []
list31 = []
list32 = []
list33 = []
list34 = []
list35 = []
list36 = []
list37 = []
list38 = []
list39 = []
list40 = []
list41 = []
list42 = []
list43 = []
list45 = []
list46 = []
list47 = []
list48 = []
list49 = []
list50 = []
list51 = []
list52 = []
fullname = ""
work = ""
edu = ""
Lives = ""
he_from = ""
relation = ""
mobile = ""
# Variables used:
# z for list locating
# as you see each date in a new list there
# p for list switching
# and ws for scrolling
if __name__ == '__main__':
# Login Progress
dri.get("https://www.facebook.com/")
time.sleep(3)
dri.find_element_by_id("email").send_keys(email)
dri.find_element_by_id("pass").send_keys(password)
dri.find_element_by_name("login").click()
time.sleep(3)
# Scraping Data
for fik in heads:
# Check if one of wanted data from about overview data
if fik in str(["Name", "Job", "Education", "Living in", "From", "Relationship", "Mobile"]):
time.sleep(3)
dri.get("https://www.facebook.com/profile.php?&sk=about_overview")
time.sleep(5)
if fik in "Name":
fullname = str(dri.find_element_by_xpath(
"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div/div/div[1]/div[2]/div/div/div[2]/div/div/div/div[1]/div/div/span/h1").text)
if fik in "Job":
try:
work = str(dri.find_element_by_xpath(
"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div/div/div[4]/div/div/div/div[1]/div/div/div/div/div[2]/div/div/div/div[1]/div/div/div[1]/div/div[2]/div").text)
except:
work = ""
pass
if fik in "Education":
try:
edu = str(dri.find_element_by_xpath(
"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div/div/div[4]/div/div/div/div[1]/div/div/div/div/div[2]/div/div/div/div[2]/div/div/div[1]/div/div[2]/div[1]").text)
except:
edu = ""
pass
if fik in "Living in":
try:
Lives = str(dri.find_element_by_xpath(
"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div/div/div[4]/div/div/div/div[1]/div/div/div/div/div[2]/div/div/div/div[3]/div/div/div[1]/div/div[2]/div").text)
except:
Lives = ""
pass
if fik in "From":
try:
he_from = str(dri.find_element_by_xpath(
"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div/div/div[4]/div/div/div/div[1]/div/div/div/div/div[2]/div/div/div/div[4]/div/div/div[1]/div/div[2]/div").text)
except:
he_from = ""