Skip to content

Instantly share code, notes, and snippets.

@kotnik
Created May 7, 2014 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kotnik/7738fccd6f8dbfa966fc to your computer and use it in GitHub Desktop.
Save kotnik/7738fccd6f8dbfa966fc to your computer and use it in GitHub Desktop.
import time
import contextlib
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
FB_USER = "YOUR FACEBOOK MAIL"
FB_PASS = "YOUR FACEBOOK PASSWORD"
backoff_time = 5
with contextlib.closing(webdriver.Firefox()) as driver:
driver.get("http://www.facebook.org")
assert "Facebook" in driver.title
elem = driver.find_element_by_id("email")
elem.send_keys(FB_USER)
elem = driver.find_element_by_id("pass")
elem.send_keys(FB_PASS)
elem.send_keys(Keys.RETURN)
time.sleep(1)
user_link = driver.find_elements_by_xpath("//*[@id='pageNav']/li[1]/a")[0].get_attribute("href")
user_link_url = user_link.split('?')[0]
user_id = user_link_url.split('/')[-1]
all_posts_page = "https://www.facebook.com/%s/allactivity?privacy_source=activity_log&log_filter=cluster_11" % user_id
there_are_stories = True
while there_are_stories:
driver.get(all_posts_page)
time.sleep(backoff_time)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(backoff_time / 2)
modify_popups = driver.find_elements_by_xpath("//div[contains(@class,'uiPopover')]/a")
for link in modify_popups:
if link.is_displayed():
link.click()
time.sleep(1)
del_links = driver.find_elements_by_xpath("//span[contains(.,'Delete') and contains(@class,'_')]/../..")
for d_link in del_links:
if d_link.is_displayed():
d_link.click()
time.sleep(3)
buttons = driver.find_elements_by_xpath("//button[contains(@class,'layerConfirm')]")
if len(buttons) != 0:
buttons[0].click()
time.sleep(6)
break
else:
backoff_time += 5
if backoff_time > 120:
there_are_stories = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment