imageshack 上传脚本 ── 改进版

前几天介绍的 imageshack 上传脚本 有一个缺点, 就是 imageshack 会不时修改上传页面, 导致使用模拟方法的脚本失效. 而且每次都要先下载上传页面, 比较慢. 于是我就想到了将上传页面放在本地:

将 imgshack 脚本改成这样(感谢:老狼):

#!/usr/bin/perl -w
use strict;
use WWW::Mechanize;
use FindBin qw($Bin);

# suppress warnings about malformed forms
$SIG{__WARN__} = sub {} ;

my $url = "file://$Bin/imgshack_client.html";

my $mech = WWW::Mechanize->new();

foreach (@ARGV)
{
    $mech->get($url);

    $mech->form_number(1);
    $mech->field('fileupload' => $_);
    $mech->submit();

    # follow the link to see the image
    $mech->follow_link( text => 'Show', n => 1 );

    # display the URL of the uploaded image
    print (($mech->images())[0]->url() . "\n");
}

然后在脚本的相同目录下建一个网页文件 imgshack_client.html :

<html>
    <head></head>
    <body>
        <form action="http://load.imageshack.us/" method="post" enctype="multipart/form-data" target="_blank">
            <input name="fileupload" type="file">
            <input type="submit">
        </form>
    </body>
</html>

这样的话就不受远程上传页面的控制了

This entry was posted on 星期日, 7月 1st, 2007 at 11:00 上午 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. 归档