-
Notifications
You must be signed in to change notification settings - Fork 0
/
facebook.py
45 lines (44 loc) · 2.09 KB
/
facebook.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
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
import time
import bs4
import getpass
from selenium.common import exceptions
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(ChromeDriverManager().install(),chrome_options=chrome_options)
driver.get("https://m.facebook.com")
driver.maximize_window()
username = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='email']")))
password = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='pass']")))
username.clear()
username.send_keys("01963**")
password.clear()
password.send_keys("*****")
# password=getpass.getpass()
time.sleep(10)
button = WebDriverWait(driver, 2).until(EC.element_to_be_clickable((By.XPATH, "//button[@name='login']"))).click()
time.sleep(5)
driver.get("https://m.facebook.com/banglalinkdigital/?tsid=0.8277416894125471&source=result")
time.sleep(8)
check_height = driver.execute_script("return document.body.scrollHeight;")
while True:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(1)
height = driver.execute_script("return document.body.scrollHeight;")
if height == check_height:
break
check_height = height
time.sleep(10)
comment=driver.find_element(By.XPATH,"//div[@id='feedback_inline_pfbid02adSwjA9wwgCqzKzoJcBjCLreRdqtmjGAkcYxmBpauFkPLpksfSeJCekgyFL8J6nml']//a[@class='_15kq _77li'][normalize-space()='Comment']").click()
time.sleep(5)
all_comments=driver.find_elements(By.XPATH,"//div[@class='_2b04']")
for f in all_comments:
comment=f.find_element(By.CSS_SELECTOR,"div[data-commentid]").text
print(comment)
time.sleep(5)