[Wikipedia-l] Uploading files?

Erik Moeller erik_moeller at gmx.de
Sun Nov 30 23:30:05 UTC 2003


Karl-
> Is there a better way than uploading files with
> http://de.wikipedia.org/wiki/Spezial:Upload ?  This is much too slow
> (too many clicks) if you want to upload more than a single file.

Try this Perl script (replace string constants accordingly). You need to  
be logged in, so copy your cookies.txt to the directory where the script  
is run:

#!/usr/bin/perl
my @files=glob("fayum-??.jpg");
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
use HTML::LinkExtor;
use HTTP::Cookies;
my $browser=LWP::UserAgent->new();
  my @ns_headers = (
   'User-Agent' => 'Mozilla/4.76 [en] (Win98; U)',
   'Accept' => 'image/gif, image/x-xbitmap, image/jpeg,
        image/pjpeg, image/png, */*',
   'Accept-Charset' => 'iso-8859-1,*,utf-8',
   'Accept-Language' => 'en-US',
  );
$browser->cookie_jar( HTTP::Cookies::Netscape->new('file' => 'cookies.txt'));

  foreach $file(@files) {
my $response=$browser->post("http://www.wikipedia.org/wiki/Special:Upload",
@ns_headers,Content_Type=>'form-data',Content=>
[
wpUploadFile=>[$file],
wpUploadDescription=>"Large version of portrait for [[Gallery of Fayum mummy portraits]].
Scanned and/or edited by [[User:Eloquence|Eloquence]], [[public domain]] picture.",
wpUploadAffirm=>"1",
wpUpload=>"Upload file",
wpIgnoreWarning=>"1"
]);
push @responses,$response->content;
  }
open(RESPO,">responses.txt");
print RESPO @responses;
close(RESPO);



More information about the Wikipedia-l mailing list