Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: How to get/save image with LWP

by marto (Cardinal)
on Jul 07, 2021 at 21:46 UTC ( #11134779=note: print w/replies, xml ) Need Help??


in reply to How to get/save image with LWP

A mojo based proof of concept. Feel free to add error checking etc:

#!/usr/bin/perl use strict; use warnings; use Mojo::UserAgent; my $url = 'https://en.wikipedia.org/wiki/File:ENIAC-changing_a_tube.jp +g'; my $ua = Mojo::UserAgent->new; my $dom = $ua->get( $url )->res->dom; my $target = $dom->at('#file > a:nth-child(1) > img:nth-child(1)')->at +tr('src'); $ua->get('https:' . $target)->res->save_to('target.jpg') ;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11134779]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2022-05-25 17:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (90 votes). Check out past polls.

    Notices?