自動轉貼圖片

Perl 寫了一支小程式,用 WWW::Mechanize 把某個 url 抓下來再貼到 ImageVenue 上:

#!/usr/bin/perl

use File::Basename;
use Getopt::Std;
use WWW::Mechanize;
use strict;

my %opt;
getopts('dp:', \%opt);

my $debug = 0;
$debug = 1 if (defined($opt{'d'}));

my $proxy;
if (defined($opt{'p'}))
{
  $proxy = $opt{'p'};
}
elsif (defined($ENV{'http_proxy'}))
{
  $proxy = $ENV{'http_proxy'};
}

my $url = shift() or die();

chdir('/tmp');
&main();

sub main
{
  my $outfile = sprintf('%s', basename($url));
  print('* Filename: ', $outfile, "\n");

  # Get
  my $agent = WWW::Mechanize->new();
  $agent->proxy($proxy) if ($proxy ne '');
  $agent->get($url);

  my $content = $agent->content();

  open(O, '> ' . $outfile);
  print(O $content);
  close(O);

  print('* Filesize: ', length($content), "\n");

  # then upload
  $agent->get('http://www.imagevenue.com/');
  $agent->form_number(1);
  $agent->field('file1', $outfile);
  $agent->submit();

  print($agent->content()) if ($debug);

  # tell me the url
  $agent->form_name('form8');
  my $imgurl = $agent->value('select');
  chomp($imgurl);
  $imgurl =~ s/\s+//g;

  print('* Output URL: ', $imgurl, "\n");

  # delete temp file
  unlink($outfile);
}

One thought on “自動轉貼圖片”

  1. 前陣子我也寫了類似的東西, 把從某日本*大*圖站的東西咪下來的庫存, 轉貼到2cha裡面去….
    每一區保留 2000 張圖片, 總共吃掉 6xxMB 空間的樣子… (默)

Comments are closed.