I see, learn and rediscover… everyday!
 
Remove all your friends from Facebook.

Remove all your friends from Facebook.

Very rarely, you will want to delete all friends from Facebook and start a “fresh” facebook account.

Now, it’s hard to do this manually. Thanks to phpunit + selenium + a few lines of code, this can be done now.

The following script removes all your friends from facebook 🙂 Replace and with your username and password respectively.


<?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class Example extends PHPUnit_Extensions_SeleniumTestCase
{
  protected function setUp()
  {
    $this->setBrowser("*chrome");
    $this->setBrowserUrl("http://www.facebook.com/");
  }
  public function testMyTestCase()
  {
    $this->open("/");
    $this->type("email", "<username>");
    $this->type("pass", "<password>");
    $this->click("//input[@value='Login']");
    $this->waitForPageToLoad("90000");
    for($i=0; $i<1000; $i++) {
        $this->click("link=Profile");
        $this->waitForPageToLoad("90000");
        $this->click("//a[@href='http://www.facebook.com/sp2hari?sk=friends&v=friends']");
        $this->waitForPageToLoad("90000");
        $this->click("//div[@class='fbProfileLargePortrait']/a/");
        $this->waitForPageToLoad("90000");
        $this->click("link=Unfriend");
        sleep(5);
        $this->click("remove-friend");
        $this->waitForPageToLoad("90000");
    }
  }
}
?>

Note:
1. The script will stop in between with timeout error. You probably should run this script in an infinite loop.
2. Once you’ve reached 0 friends, facebook blocks you from adding friends in bulk for 2 days. So, you probably have to wait till facebook trusts you as human and not a bot. 🙂

Happy hacking 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.