-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFacebook Friendlist Scraper.py
73 lines (51 loc) · 2.01 KB
/
Facebook Friendlist Scraper.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
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
user_id=input('Enter User Id of your Fb Account :') # Take user id and password as input from the user
password=input('Enter the password :')
print(user_id)
print(password)
cd='C:\\chromedriver.exe'
browser= webdriver.Chrome(cd)
browser.get('https://www.facebook.com/')
user_box = browser.find_element_by_id("email") # For detecting the user id box
user_box.send_keys(user_id) # Enter the user id in the box
password_box = browser.find_element_by_id("pass") # For detecting the password box
password_box.send_keys(password) # For detecting the password in the box
login_box = browser.find_element_by_id("u_0_b") # For detecting the Login button
login_box.click() # To click on the login box
time.sleep(20)
pro=browser.find_element_by_xpath('//*[@id="mount_0_0"]/div/div[1]/div[1]/div[2]/div[4]/div[1]/div[1]/a')
pro.click()
time.sleep(4)
fr=browser.find_element_by_xpath('//*[@id="mount_0_0"]/div/div[1]/div[1]/div[3]/div/div/div[1]/div[1]/div/div/div[4]/div[2]/div/div[1]/div[2]/div[2]/div[3]/div/div/div/div[1]/div/div/div/div[1]/h2/span/div/div[1]/span/a')
fr.click()
time.sleep(4)
while True:
browser.execute_script('window.scrollTo(0,document.body.scrollHeight);')
time.sleep(0.1)
browser.execute_script('window.scrollTo(0,0);')
time.sleep(0.1)
try:
exit_control=browser.find_element_by_xpath("//*[contains(text(), 'More about you')]")
break
except:
continue
ps=browser.page_source
soup=BeautifulSoup(ps,'html.parser')
flist=soup.find('div',{'class':'_3i9'})
friends=[]
for i in flist.findAll('a'):
friends.append(i.text)
names_list=[]
for name in friends:
if(name=='FriendFriends'):
continue
if('friends' in name):
continue
if(name==''):
continue
else:
names_list.append(name)
print(names_list)