python selenium facebook scraper

Solutions on MaxInterview for python selenium facebook scraper by the best coders in the world

showing results for - "python selenium facebook scraper"
Haley
21 Jan 2021
1import time
2import re
3from selenium import webdriver
4from selenium.webdriver.common.keys import Keys
5 
6usr = "<your_facebook_email_address>"
7pwd = "<your_facebook_password>"
8 
9url = "https://mobile.facebook.com/story.php?story_fbid=10156391722455952&id=157851205951"
10driver = webdriver.Chrome('/Users/zero/Documents/GitHub/SentimentAnalysis/chromedriver')
11driver.get(url)
12 
13time.sleep(1)
14if driver.find_element_by_xpath('//*[@id="viewport"] /div/div[3] /div/div[2] 
15/div/a'):
16   driver.find_element_by_xpath('//*[@id="viewport"] /div/div[3] /div/div[2] 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30/div/a').click()
31 
32elem = driver.find_element_by_id("m_login_email")
33elem.send_keys(usr)
34 
35elem = driver.find_element_by_id("m_login_password")
36elem.send_keys(pwd)
37 
38elem.send_keys(Keys.RETURN)
39 
40hasLoadMore = True
41while hasLoadMore:
42    time.sleep(1)
43    try:
44        if driver.find_element_by_xpath('//*[@id="viewport"] /div/div[4] /div/div/div/div/div/div[2] /div/div/div[5] /*[@class="async_elem"] 
45/a'):
46            driver.find_element_by_xpath('//*[@id="viewport"] /div/div[4] /div/div/div/div/div/div[2] /div/div/div[5] /*[@class="async_elem"] 
47 
48 
49 
50/a').click()
51    except:
52        hasLoadMore = False
53 
54users_list = [] 
55 
56 
57 
58 
59 
60 
61 
62users = driver.find_elements_by_class_name('_2b05')
63 
64for user in users:
65    users_list.append(user.text)
66     
67i = 0
68texts_list = [] 
69 
70 
71 
72 
73texts = driver.find_elements_by_class_name('_2b06')
74 
75for txt in texts:
76    texts_list.append(txt.text.split(users_list[i] 
77 
78 
79 
80 
81 
82))
83    i += 1
84    comments_count = len(users_list)
85 
86 
87for i in range(1, comments_count):
88    user = users_list[i] 
89 
90    text = texts_list[i] 
91 
92 
93    print("User ",user)
94    print("Text ",text)
95