If you could help me on this Mech issue, I sure would appreciate it. I am trying to retrieve PDFs from a website. I am using WWW::Mechanize as follows:
my $start = "http://www.xxxx.com/programs_results/"; my $mech = WWW::Mechanize->new( autocheck => 1 ); $mech->get( $start ); my @links = $mech->find_all_links( url_regex => qr/\d+.+\.pdf$/ ); chdir $progdest or die "Can't change directory: $!\n"; for my $link ( @links ) { my $url = $link->url_abs; my $filename = $url; $filename =~ s[^.+/][]; mech->get( $url, ':content_file' => $filename ); }
This code works to download PDFs, but the files on the website have duplicate names, differentiated only by their links.

The pdf names are downloaded as "_20090326.pdf."

The links from the source are in the following pattern: /pdf/100004/_20090326.pdf, /pdf/100006/_20090326.pdf etc.

So not all files are saved since some are overwritten. I believe that a different regex is needed, and that's where I am stuck.

I need the other files with the same names.

So the solution would be to get a final file name that includes more of the link such as "100004_20090326.pdf," "100006_20090326.pdf," etc.

Could you help me with the modifications to the code above that would produce this result?

In reply to Question about WWW::Mechanize by palsy017

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.