Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] get troubles in fetch images from web using perl

Expand Messages
  • timothy adigun
    Hi ssysong, ... You can use getstore subroutine from LWP::Simple, to store the pictures on your local drive. like thus: [CODE] #!/usr/bin/perl use warnings;
    Message 1 of 4 , May 1, 2013
    • 0 Attachment
      Hi ssysong,
      On 4/27/13, ssysong <ubuntubiker@...> wrote:
      > i want to fetch images from www.baidu.com. i use the LWP module.i can get
      > the image urls,but i can not download it.
      > look forward ur helps.
      >
      You can use "getstore" subroutine from LWP::Simple, to store the
      pictures on your local drive. like thus:
      [CODE]
      #!/usr/bin/perl
      use warnings;
      use strict;
      use HTML::TreeBuilder;
      use LWP::Simple qw(get getstore);

      my $base_url = 'http://image.baidu.com/';
      my $tree = HTML::TreeBuilder->new;

      $tree->parse( get($base_url) );
      $tree->eof;

      for ( $tree->look_down( '_tag', 'img' ) ) {
      my $name = $_->attr('data-src') || next;
      getstore(
      $name,
      do {
      ( my $new_name = $name ) =~ s/^.*?\/(\w+?\.\w{3})$/$1/;
      $new_name;
      }
      );
      }
      $tree->delete();
      [/CODE]
      Hope this helps.
      > [Non-text portions of this message have been removed]
      >
      >


      --
      Tim
    • ssysong
      it really works,thx [Non-text portions of this message have been removed]
      Message 2 of 4 , May 1, 2013
      • 0 Attachment
        it really works,thx

        [Non-text portions of this message have been removed]
      • merlynstonehengecom
        ... timothy You can use getstore subroutine from LWP::Simple, to store the timothy pictures on your local drive. like thus: mirror() is even better,
        Message 3 of 4 , May 2, 2013
        • 0 Attachment
          >>>>> "timothy" == timothy adigun <2teezperl@...> writes:

          timothy> You can use "getstore" subroutine from LWP::Simple, to store the
          timothy> pictures on your local drive. like thus:

          mirror() is even better, because if you already have the file, it
          fetches it only if it has been updated.

          And also:

          **************************************************
          *
          * THIS IS NOT THE OFFICIAL perl BEGINNERS GROUP.
          *
          * The official one is at beginners@..., with instructions on how to
          * join at http://lists.perl.org/list/beginners.html.
          *
          * You'll get far better response there, not to say you won't get *any* here.
          *
          **************************************************

          --
          Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
          <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
          Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
          See http://methodsandmessages.posterous.com/ for Smalltalk discussion
        Your message has been successfully submitted and would be delivered to recipients shortly.