Skip to content

Instantly share code, notes, and snippets.

@CLCL
Last active August 29, 2015 14:19
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 CLCL/f3519894d6a8a3d1f52a to your computer and use it in GitHub Desktop.
Save CLCL/f3519894d6a8a3d1f52a to your computer and use it in GitHub Desktop.
PukiWikiの特定ページに鬼の様な大量のSPAM添付ファイルがぶっこまれた時、PerlのヘッドレスブラウザモジュールのWWW::Mechanizeを使って消します。
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use WWW::Mechanize;
# deldel.pl PukiWikiのページ内添付ファイルを根こそぎ消す
my $pageurl = 'http://dtpwiki.jp/index.php?Perl';
my $password = 'naishodayo';
my $mech = WWW::Mechanize->new;
$mech->agent_alias('Mac Safari');
$mech->get($pageurl);
my @links = $mech->find_all_links( tag => "a", text_regex => qr/詳細/i );
foreach my $link ( @links ) {
my $url = $link->url();
next if $url =~ m/kannren2.gif/;
next if $url =~ m/kannren1.gif/;
next if $url =~ m/E8%89%B2%E6%B7%B7_ver2.txt/;
print "$url\n";
go_shousai( $link );
#sleep 1;
}
sub go_shousai {
my $link = shift;
$mech->get( $link );
# die $mech->content();
$mech->field("pcmd", "delete");
$mech->submit_form(
fields => {
pass => $password,
},
);
}
requires 'WWW::Mechanize';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment