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.
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.