Lonnie Knows Everything

Use perl to automatically delete your facebook wall posts!

by Lonnie on May.06, 2010, under Linux, Nerd Stuff, Programming

UPDATE: as of 11/30/2011 I have abandoned this all together, I use cleanmywall.net, or did until it went down .. you can now use this link for your cleaning needs.

UPDATE: as of 12/13/2010 I have a greasemonkey script for firefox that works much better than this.. http://userscripts.org/scripts/show/92664

Continue reading if you want :)

OK I won’t lie, this was cobbled together quickly .. and it will only delete so many at a time so you’ll need to run it a few times if you’ve got a lot of posts, I could make it so that it loops and deletes everything but I wanted to put it out there.

Use it at your own risk! if you get banned from facebook for automating something then that’s your own fault.. this is purely for educational purposes only and all that jazz =) *wink wink*
Continue on reading!..

This code will log you in, go to m.facebook.com/minifeed.php and pull a list of stories then will loop through and delete them with a 5 second rest between deletes..  (less obvious) .. it also pretends to be firefox.

This requires WWW::Mechanize, HTTP::Cookies, HTML::Parser and HTML::TagParser .. ENJOY!

#!/usr/bin/perl
use WWW::Mechanize;
use HTTP::Cookies;
use HTML::Parser;
use HTML::TagParser;

my $username = “user@domain.com”;
my $password = “password”;
my $mech = WWW::Mechanize->new();

$mech->agent_alias( ‘Linux Mozilla’ );
$mech->cookie_jar(HTTP::Cookies->new());
$mech->post(“https://login.facebook.com/login.php?m&next=http://m.facebook.com/minifeed.php”,{email=>$username,pass=>$password});
my $test = $mech->content();
$mech->content() =~ /url=(.*?)”/;
my $newurl = $1;

$mech->get($newurl);

my $html = $mech->content();

my $parser = HTML::Parser->new( api_version => 3,start_h => [&start,"tagname, attr"], );
my @links;
sub start {
my ($tag, $attr) = @_;
if ($tag =~ /^a$/ and defined $attr->{href}) {
return
if ($attr->{href} =~ m!^http://! and $opts{r}); # exclude absolute url when -r
return
if ($attr->{href} !~ m!http://! and $opts{a});# exclude relative url when -a
push @links, $attr->{href};
}
}
$parser->parse($html);
$parser->eof;

foreach $link (@links) {
if ($link =~ /delete.php/) {
$mech->get(“http://m.facebook.com” . $link);

$html_p = HTML::TagParser->new( $mech->content() );
@elem = $html_p->getElementsByTagName( “form” );
$action = $elem[0]->getAttribute(“action”);

@elem = $html_p->getElementsByAttribute( “name”, “fb_dtsg” );
$fb_dtsg = $elem[0]->getAttribute(“value”);

@elem = $html_p->getElementsByAttribute( “name”, “ministory_key” );
$ministory_key = $elem[0]->getAttribute(“value”);

@elem = $html_p->getElementsByAttribute( “name”, “story_type” );
$story_type = $elem[0]->getAttribute(“value”);

@elem = $html_p->getElementsByAttribute( “name”, “profile_id” );
$profile_id = $elem[0]->getAttribute(“value”);

@elem = $html_p->getElementsByAttribute( “name”, “confirm” );
$confirm_id = $elem[0]->getAttribute(“value”);

print “Deleting mini story key: $ministory_key..n”;
$mech->post(“http://m.facebook.com” . $action,
{fb_dtsg=>$username,
ministory_key=>$ministory_key,
story_type=>$story_type,
profile_id=>$profile_id,
confirm_id=>$confirm_id});
sleep(5);

}

VN:F [1.9.3_1094]
Rating: +1 (from 1 vote)

Incoming search terms:

  • auto delete facebook posts
  • facebook auto remove posts
  • Facebook Auto Delete posts
  • perl facebook
  • fb_dtsg
  • automatically delete facebook posts
  • facebook auto delete
  • delete facebook wall
  • facebook perl
  • login facebook perl search
:

4 Comments for this entry

  • lslah

    Wow, that’s great! I was just looking around for an example of using HTML::Parser. Great :-)

    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
  • Michael

    Hello,

    this is a great script. Perl is not my favorite language.

    Is there a way to post another script which deletes special wall post from farmville.

    Would be glad about any help

    Michael

    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
  • PerlTidy

    Thank you and thanks to perltidy for that :

    #!/usr/bin/perl
    use WWW::Mechanize;
    use HTTP::Cookies;
    use HTML::Parser;
    use HTML::TagParser;
    my $username = “EMAIL”;
    my $password = “PASSWORD”;
    my $mech = WWW::Mechanize->new();
    $mech->agent_alias(‘Linux Mozilla’);
    $mech->cookie_jar( HTTP::Cookies->new() );
    $mech->post(
    “https://login.facebook.com/login.php?m&next=http://m.facebook.com/minifeed.php”,
    { email => $username, pass => $password }
    );
    my $test = $mech->content();
    $mech->content() =~ /url=(.*?)”/;
    my $newurl = $1;
    $mech->get($newurl);
    my $html = $mech->content();
    my $parser = HTML::Parser->new(
    api_version => 3,
    start_h => [ &start, "tagname, attr" ],
    );
    my @links;

    sub start {
    my ( $tag, $attr ) = @_;
    if ( $tag =~ /^a$/ and defined $attr->{href} ) {
    return
    if ( $attr->{href} =~ m!^http://! and $opts{r} )
    ; # exclude absolute url when -r
    return
    if ( $attr->{href} !~ m!http://! and $opts{a} )
    ; # exclude relative url when -a
    push @links, $attr->{href};
    }
    }
    $parser->parse($html);
    $parser->eof;
    foreach $link (@links) {
    if ( $link =~ /delete.php/ ) {
    $mech->get( “http://m.facebook.com” . $link );
    $html_p = HTML::TagParser->new( $mech->content() );
    @elem = $html_p->getElementsByTagName(“form”);
    $action = $elem[0]->getAttribute(“action”);
    @elem = $html_p->getElementsByAttribute( “name”, “fb_dtsg” );
    $fb_dtsg = $elem[0]->getAttribute(“value”);
    @elem = $html_p->getElementsByAttribute( “name”, “ministory_key” );
    $ministory_key = $elem[0]->getAttribute(“value”);
    @elem = $html_p->getElementsByAttribute( “name”, “story_type” );
    $story_type = $elem[0]->getAttribute(“value”);
    @elem = $html_p->getElementsByAttribute( “name”, “profile_id” );
    $profile_id = $elem[0]->getAttribute(“value”);
    @elem = $html_p->getElementsByAttribute( “name”, “confirm” );
    $confirm_id = $elem[0]->getAttribute(“value”);
    print “Deleting mini story key: $ministory_key..n”;
    $mech->post(
    “http://m.facebook.com” . $action,
    {
    fb_dtsg => $username,
    ministory_key => $ministory_key,
    story_type => $story_type,
    profile_id => $profile_id,
    confirm_id => $confirm_id
    }
    );
    sleep(5);
    }
    }

    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
  • Lonnie

    Thanks for the update .. I’ve personally not made any effort to update the perl script because I’m instead using a bookmarklet ..

    I snatched the code from cleanmywall.net ( or com, I forget now ) and modified it a bit and I simply use it.. I find it to be much nicer, it’s also very fast..

    It’s simply a bookmarklet with a gui .. it will continue to function until facebook switches to the timeline feature which seems to be a long time off at this point.

    VN:F [1.9.3_1094]
    Rating: 0 (from 0 votes)

2 Trackbacks / Pingbacks for this entry

Leave a Reply



Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...