Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Download a file with WWW::Mechanize

by Limbic~Region (Chancellor)
on Apr 21, 2013 at 04:26 UTC ( [id://1029703]=perlquestion: print w/replies, xml ) Need Help??

Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:

All,
If you open this link up in your browser, it will probably start downloading the subtitles (.srt file) to the first episode of Bates Motel. When I fetch the page with WWW::Mechanize though, I get HTML with no apparent way to get at the file.

I am pretty bleary eyed from a 24 hour coding session so I am sure I am missing something simple. I looked at it through firebug but didn't see what I was missing.

What should I be doing?

Cheers - L~R

Replies are listed 'Best First'.
Re: Download a file with WWW::Mechanize
by Gangabass (Vicar) on Apr 21, 2013 at 06:02 UTC
    I'm sure this is not WWW::Mechanize issue because this simple script works for me:
    #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); #$mech->agent_alias("Windows IE 6"); $mech->get("http://dl.opensubtitles.org/en/download/file/1953419460"); $mech->save_content("result.srt");
    What HTML do you have?
      Gangabass,
      I slept for 10 hours and haven't had a chance to test the code (which obviously was a small piece of a much larger script). I assume you are right and that the problem was elsewhere. I will see what happens and report back if still having problems.

      Update: Yep. I wasn't bothering to verify I was fetching the URL I thought I was. Instead of http://dl.opensubtitles.org/en/download/file/1953419460, I was grabbing http://dl.opensubtitles.org/en/download/file1953419460.

      Cheers - L~R

        $mech->show_progress(1);
Re: Download a file with WWW::Mechanize
by BrowserUk (Patriarch) on Apr 21, 2013 at 06:29 UTC

    This works:

    wget "http://dl.opensubtitles.org/en/download/file/1953419460"

    Albeit that you'd have to rename the file afterward.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      BrowserUk,
      Which likely means the problem exists elsewhere. I probably should have known better than to continue coding beyond the point of exhaustion. English is my wife's 3rd language and getting subtitles for her is almost a necessity. Update: Yes, the problem existed between the keyboard and chair. I just verified I was missing a / delimiter in my URL.

      Cheers - L~R

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-20 06:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found