Página 1 de 1

Descargar imágenes

NotaPublicado: 2008-10-02 23:26 @018
por charly
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:

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
#!/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" );
}
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4


Me descarga las imágenes pero al momento de abrirlas no se ve nada. Nuevamente les pido su ayuda, por favor.

NotaPublicado: 2008-10-03 03:08 @172
por explorer
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.

Re: Descargar imágenes

NotaPublicado: 2008-10-07 16:33 @731
por natxo
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 ;-)

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
#!/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 => '[email protected]',
                To => '[email protected]',
                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";
        }
    }
}
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4