方便的 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 星期六, 6月 30th, 2007 at 8:40 下午 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.

没有评论

Be the first to comment on this entry.

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.

  1. Welcome ~

    Life is like a box of chocolates,
    you never know
    what you gonna get.


  2. 因为某原因, google blog 暂时停止更新..
    by AutumnCat, 2007-6-12
  3. 最新文章

  4. 最新评论

  5. 分类

  6. 归档