方便的 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 … )
This entry was posted on Saturday, June 30th, 2007 at 8:40 pm and is filed under Linux, PERL, Programming. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Have your say
Fields in bold are required. Email addresses are never published or distributed.
Some HTML code is allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>URIs must be fully qualified (eg: http://www.domainname.com) and all tags must be properly closed.
Line breaks and paragraphs are automatically converted.
Please keep comments relevant. Off-topic, offensive or inappropriate comments may be edited or removed.