30th Jun 2007
方便的 imageshack 上传脚本
自从有了 nopaste 脚本, 贴文字信息(特别是程序输出)就成了件很轻松的事 ── 只要灌到管道线就可以了. 但是贴图还是比较麻烦. 今日一番搜索, 找到了这个: http://www.terminally-incoherent.com/blog/2007/06/27/batch-upload-images-to-imageshack-using-perl/
#!/usr/bin/perl -w
use strict;
use WWW::Mechanize;
# suppress warnings about malformed forms
$SIG{__WARN__} = sub {} ;
my $url = "http://www.imageshack.us/";
my $mech = WWW::Mechanize->new();
foreach (@ARGV)
{
$mech->get($url);
$mech->form_number(2);
$mech->field('fileupload' => $_);
$mech->submit();
# follow the link to see the image
$mech->follow_link( text => 'Show', n => 1 );
my @im = $mech->images();
# display the URL of the uploaded image
print $im[0]->url() . "\n";
}
将该网页所示的代码另存为一个脚本, 例如 imgshack , 别忘了加上x权限, 然后
imgshack imagefile_1 [ imagefile_2 ... ]
成功上传后会输出url, 很方便.
ps: 作者在使用过程中遇到一个问题. 注意脚本中
$mech->form_number(2);
这一句. imageshack 貌似会不时调整上传页面的表单元素顺序, 所以如果某天这个脚本灵了, 可以试试将2改成其它数字(1, 3, 4 … )
Leave a Reply