Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Facebook AutoPost
#5
yes, here would be an example of logging into facebook and listing all friends. You can tweak it to do what you want.
change selenium drivers to your paths. More info here.
from selenium import webdriver
import time
import os

URL = 'https://www.facebook.com/'
CHROMEPATH = '/home/metulburr/chromedriver'
PHANTOMPATH = '/home/metulburr/phantomjs'
EMAIL = ''
PASSWORD = ''

class App:
	def __init__(self):
		self.setup_chrome()
		#self.setup_headless()
		self.login()
		self.to_home()
		self.to_friends()
		time.sleep(100000) #keep alive to view html
		
	def delay(self):
		time.sleep(3)
	
	def chrome_prep(self):
		'''get rid of asking to save password and notifications popup'''
		chrome_options = webdriver.ChromeOptions()
		chrome_options.add_experimental_option(
			'prefs', {
				'credentials_enable_service': False,
				"profile.default_content_setting_values.notifications" : 2,
				'profile': {
					'password_manager_enabled': False
				}
			}
		)
		return chrome_options
		
	def setup_chrome(self):
		options = self.chrome_prep()
		os.environ["webdriver.chrome.driver"] = CHROMEPATH
		self.browser = webdriver.Chrome(CHROMEPATH, chrome_options=options)
		self.browser.set_window_position(0,0)
		self.delay()
		
	def setup_headless(self):
		self.browser = webdriver.PhantomJS(PHANTOMPATH)
		self.delay()
		
	def login(self):
		self.browser.get(URL) 
		time.sleep(1) 
		username = self.browser.find_element_by_id("email")
		password = self.browser.find_element_by_id("pass")
		username.send_keys(EMAIL)
		password.send_keys(PASSWORD)
		login_attempt = self.browser.find_element_by_xpath("//*[@type='submit']")
		login_attempt.submit()
		self.delay()
		
	def to_home(self):
		self.browser.execute_script("document.getElementsByClassName('linkWrap noCount')[0].click()")
		self.delay()
	
	def to_friends(self):
		self.browser.execute_script("document.getElementsByClassName('_6-6')[2].click()")
		self.delay()

	def scroll_to_bottom(self):

	    SCROLL_PAUSE_TIME = 0.5
	    # Get scroll height
	    last_height = self.browser.execute_script("return document.body.scrollHeight")

	    while True:
		# Scroll down to bottom
		self.browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")

		# Wait to load page
		time.sleep(SCROLL_PAUSE_TIME)

		# Calculate new scroll height and compare with last scroll height
		new_height = self.browser.execute_script("return document.body.scrollHeight")
		if new_height == last_height:
		    break
		last_height = new_height
		
App()
Recommended Tutorials:
Reply


Messages In This Thread
Facebook AutoPost - by badpandahere - Sep-10-2017, 11:55 AM
RE: Facebook AutoPost - by wavic - Sep-10-2017, 02:37 PM
RE: Facebook AutoPost - by metulburr - Sep-10-2017, 10:30 PM
RE: Facebook AutoPost - by badpandahere - Sep-11-2017, 02:17 PM
RE: Facebook AutoPost - by metulburr - Sep-11-2017, 05:41 PM
RE: Facebook AutoPost - by badpandahere - Sep-12-2017, 11:20 AM
RE: Facebook AutoPost - by nilamo - Sep-11-2017, 09:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Automating Facebook Posts mieciow 2 1,430 Aug-07-2023, 12:34 PM
Last Post: Gaurav_Kumar
  Web scrapping login facebook credentials kosmas9 0 1,978 Aug-17-2020, 01:33 PM
Last Post: kosmas9
  How to click facebook message button JanelleGuthrie 2 2,447 May-14-2020, 06:02 PM
Last Post: Larz60+
  Application like simpler facebook wall in python framework seidman 1 3,344 Mar-11-2018, 05:07 PM
Last Post: wavic
  Need help with Django 2.0 + Facebook SDK avtrrr 4 4,644 Jan-31-2018, 08:36 AM
Last Post: Larz60+
  facebook friends crawler edithegodfather 12 21,193 Jan-15-2018, 07:07 AM
Last Post: qnkhuat
  I need request POST for Facebook in My Profile Kalet 4 4,394 Sep-27-2017, 05:53 PM
Last Post: Kalet
  facebook scraping metulburr 3 8,368 Jun-02-2017, 01:00 AM
Last Post: metulburr
  Scrape Facebook page user posts text stockholm 6 8,480 May-08-2017, 12:24 PM
Last Post: Joseph_f2

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020