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);}
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
2 Trackbacks / Pingbacks for this entry
-
How to delete ALL your Facebook Wall Posts (as required by Facebook prior to deleting/deactivating your account) « Rove Monteux
January 5th, 2011 on 6:36 am[...] script below is a fix of the script provided in “Use perl to automatically delete your facebook wall posts!“, as the new Facebook Wall broke the script, and is also an alternative to the Greasemonkey [...]
-
How to delete ALL your Facebook Wall Posts (as required by Facebook prior to deleting/deactivating your account) | Rove Monteux
November 30th, 2011 on 11:16 am[...] script below is a fix of the script provided in “Use perl to automatically delete your facebook wall posts!“, as the new Facebook Wall broke the script, and is also an alternative to the Greasemonkey [...]
October 12th, 2010 on 5:47 am
Wow, that’s great! I was just looking around for an example of using HTML::Parser. Great :-)
November 12th, 2010 on 8:13 am
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
November 28th, 2010 on 8:15 am
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);
}
}
November 30th, 2011 on 2:30 pm
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.