I am trying something new as I have a proxy to the internet for the first time. I need to download some JPG files and have written the following to do the work and it is downloading something but they are not valid JPG files. I am doing this on Win32.
Anyone have thoughts on what I am doing wrong?
#!perl.exe
use strict;
use WWW::Mechanize;
use HTTP::Cookies;
use LWP;
use LWP::DebugFile;
require HTTP::Request;
my $cookie_jar = HTTP::Cookies->new(
file => 'cookies.dat',
autosave => 1,
hide_cookie2 => 1
);
my $bot = WWW::Mechanize->new;
$bot->max_redirect(100);
$bot->cookie_jar($cookie_jar);
$bot->proxy('http', 'http://proxy.company.com:80/');
$bot->proxy('https', 'http://proxy.company.com:443/');
$bot->no_proxy('localhost', 'company.com');
$bot->credentials('DOMAIN\user','pwd');
$bot->agent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.
+3) Gecko/20060426 Firefox/1.5.0.3');
my $x = 0;
foreach $x (1..15) {
my $url = "http://www.website.com/image$x.jpg";
print "Processing: $url\n";
my $response = $bot->get($url);
my $content = $bot->content;
open F, ">image$x.jpg";
print F $content;
close F;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.