Perl en Español

  1. Home
  2. Tutoriales
  3. Foro
  4. Artículos
  5. Donativos
  6. Publicidad
 

Descargar imágenes

 
Publicar nuevo tema   Responder al tema    Foros de discusión -> Intermedio
Mensaje Jue Oct 02, 2008 10:26 pm
charly
Perlero Nuevo
Perlero Nuevo
Registrado: 30 Sep 2008
Mensajes: 4
Descargar imágenes Responder citando

Hola nuevamente amigos del foro. ¿Saben? estuve revisando el foro y vi un script hecho por explorer y kidd, que lo encontré genial, que era para bajar imágenes y quise hacer lo mismo yo pero con otra dirección y este es el script:

Perl:
#!/usr/bin/perl -w

use LWP::Simple;
use strict;
use warnings;

my $URL_BASE = 'http://archive.eso.org/asm/ambient-server?night';
my $IMG_FMT  = '%02d+Jan+2005&site=paranal';
$|++;

# Bajar los imágenes:
foreach my $dia ( 1 .. 31 ) {

    my $imagen = sprintf $IMG_FMT, $dia;
    print "Bajando imagen $dia\n";
    mirror( "$URL_BASE=$imagen", "$dia.jpg" );
}


Me descarga las imágenes pero al momento de abrirlas no se ve nada. Nuevamente les pido su ayuda, por favor.
Mensaje Vie Oct 03, 2008 2:08 am
explorer
Moderador
Moderador
Registrado: 24 Jul 2005
Mensajes: 4082
Ubicación: Valladolid, España
Responder citando

El URL que está formando el programa corresponde a una página web, no a las imágenes que te quieres bajar.

Debes investigar un poco más el contenido de la página para saber exactamente las URL de esas imágenes.
Mensaje Mar Oct 07, 2008 3:33 pm
natxo
Perlero Nuevo
Perlero Nuevo
Registrado: 09 Ago 2007
Mensajes: 23
Ubicación: Países Bajos
Re: Descargar imágenes Responder citando

Hace tiempo hice un programilla para enviarme las viñetas de algunos humoristas de El País por correo. A lo mejor te sirve para inspirarte. Seguro que se puede hacer mejor o más corto, pero a mí me sirve para lo que lo hice Wink

Perl:
#!/usr/bin/perl

use strict;
use warnings;
use WWW::Mechanize;
# use LWP::Debug qw(+);

my ($url,@links,$mech,$vineta);

$url = "http://www.elpais.com";

# lo primero, bajo la página inicial de El País
$mech = WWW::Mechanize->new(autocheck =>1);
$mech->agent_alias( 'Windows IE 6');
$mech->get($url);
die "cannot get the page: ", $mech->response->status_line
    unless $mech->success;

# aquí ejecuto la función getlink
getlink("El Roto");
getlink("Romeu");
getlink("Forges");

# getlink() sólo usa un argumento: el nombre del dibujante
# así encontramos el enlace a la viñeta
sub getlink {
    @links = $mech->find_link(
        tag => "a",
        text_regex => qr/.*$_[0].*/i,
    );
 
    # give some output when run interactively
    print "Fetching cartoon $_[0]....\n";

    # here we get the actula url to the cartoon
    for (@links) {
        my $href = $_->url;
        $vineta = "$url$href";
    }

    # we make another mechanize object to fecth the image and dump it to a file in
    # /tmp
    my $m = WWW::Mechanize->new(autocheck => 1);
    $m->get($vineta);
    my @links2 = $m->find_image( alt => "$_[0]", n => 2);
    if ($m->success){
        for (@links2){
            my $imageurl = $_->url;
            my $imagelink = "$url$imageurl";
            $m->get("$imagelink", ":content_file" => "/tmp/$_[0].gif");

            # finally we make a mail object and send the file as an attachment to the
            # message
            use MIME::Lite;
            my $msg = MIME::Lite->new(
                From => 'user@example.com',
                To => 'user@example.com',
                Subject => "$_[0]",
                Type => 'multipart/mixed');
                $msg->attach(Type =>'TEXT', Data => "$_[0]");
            $msg->attach(   Type => 'image/gif',
                Path => "/tmp/$_[0].gif",
                Filename => "$_[0].gif");
            $msg->send();

            # print more interactive output
            print "Message $_[0] sent!\n";
        }
    }
}
Publicar nuevo tema   Responder al tema    Foros de discusión -> Intermedio Todas las horas son GMT - 6 Horas
Página 1 de 1



Powered by phpBB © 2001, 2005 phpBB Group