rbhyland has asked for the wisdom of the Perl Monks concerning the following question:
I am using the following code to try to get the src attribute from all the img tags from a webcomic
I get the whole page when I "print response->decoded_content;", but I don't get anything from the get-tag line. What am I doing wrong? I am running this on a windows machine.#!"C:\xampp\perl\bin\perl.exe" use strict; use warnings; use LWP::UserAgent; use CGI qw(:standard :cgi-lib -debug fatalsToBrowser warningsToBrowser +); use HTML::TokeParser; my $cgi = new CGI; print $cgi->header(); print start_html(-title =>'Save QC'); print "Starting...",br; my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->env_proxy; $ua->agent('Mozilla/5.0 Windows Gecko/30.0 Firefox/30.0'); my $response = $ua->get('http://questionablecontent.net/'); if ($response->is_success) { # print $response->decoded_content; # or whatever print br,br,"Success!"; my $tp = HTML::TokeParser->new(\$response) || die "Can't open: $!" +; while (my $token = $tp->get_tag('img')) { my $src = $token->[1]{'src'}; print "src =",$src,br } } else { print $response->decoded_content; # or whatever print br,br,"Failure!"; die $response->status_line; } print end_html;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: HTML::TokeParser not giving any tokens.
by jellisii2 (Hermit) on Dec 01, 2014 at 12:55 UTC | |
by rbhyland (Acolyte) on Dec 01, 2014 at 13:45 UTC | |
Re: HTML::TokeParser not giving any tokens.
by karlgoethebier (Abbot) on Dec 01, 2014 at 13:06 UTC | |
by rbhyland (Acolyte) on Dec 01, 2014 at 13:47 UTC |
Back to
Seekers of Perl Wisdom