title: How can I scrape images off of a webage using Perl
body: <p>I would like to scrape all images off of a webpage and am running into a problem I don't understand.</p>
  
  <p>For instance if I use enter <a href="https://www.google.com/search?as_st=y&amp;tbm=isch&amp;hl=en&amp;as_q=%22escape%20room%22%20movie%20poster&amp;safe=images" rel="nofollow noreferrer">https://www.google.com/search?as_st=y&amp;tbm=isch&amp;hl=en&amp;as_q=%22escape%20room%22+movie+poster&amp;safe=images</a> into my browser and then use the browser's "View Source" option I get a massive amount of text/code. Using "find" I get more than 400 instances of </p>
  
  <blockquote>
    <p>https://</p>
  </blockquote>
  
  <p>So the simple code I wrote (below) gets the content and writes the result to a file.  But a grep search of https:// only returns 7 instances.  So obviously I am doing something incorrectly, perhaps the page is dynamic and I can't access that part?</p>
  
  <p>Is there a way I can get the same source, via Perl, that I get via View Source?</p>
  
  <pre><code>my $ua = new LWP::UserAgent;
  $ua-&gt;agent("$0/0.1 " . $ua-&gt;agent);
  $ua-&gt;agent("Mozilla/8.0");
  
  my $sstring = "https://www.google.com/search?as_st=y&amp;tbm=isch&amp;hl=en&amp;as_q=%22escape%20room%22+movie+poster&amp;safe=images";     
  
  my $req = new HTTP::Request 'GET' =&gt; $sstring;
  $req-&gt;header('Accept' =&gt; 'text/html');
  
  my $res = $ua-&gt;request($req);
  
  open(my $fh, '&gt;', 'report.txt');
  print $fh $res-&gt;decoded_content;
  close $fh;
  </code></pre>
  
  <p>Here's the example I got from WWW:Mechanize::Chrome</p>
  
  <pre><code>my $mech = WWW::Mechanize::Chrome-&gt;new();
  my $sstring = "https://www.google.com/search?as_st=y&amp;tbm=isch&amp;hl=en&amp;as_q=\"" . $arrayp . "\"" . "+movie+poster&amp;safe=images";        
  $mech-&gt;get($sstring);
  
  sleep 5;
  
  print $_-&gt;get_attribute('href'), "\n\t-&gt; ", $_-&gt;get_attribute('innerHTML'), "\n"
            for $mech-&gt;selector('a.download');
  </code></pre>