Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

LWP::Simple trouble. [SOLVED]

by scarfguy (Novice)
on May 16, 2016 at 17:10 UTC ( [id://1163147]=perlquestion: print w/replies, xml ) Need Help??

scarfguy has asked for the wisdom of the Perl Monks concerning the following question:

So close, but yet so far!

I try to download a .zip file from a site, which I navigated and logged in to, using WWW::Mechanize. The url ends with .../pluginfile.php/randomStuff/myFile.zip?forcedownload=1. If I navigate to this link by hand, a window opens and asks me where to save the file. This is the php stuff? How do I get past this window in my script?

I attempt to download the file with  getstore($downloadLink, $fileName);. But instead of downloading the .zip file, it saves an html-file. :( . Any thoughts?

Replies are listed 'Best First'.
Re: LWP::Simple trouble.
by haukex (Archbishop) on May 16, 2016 at 20:10 UTC

    Hi scarfguy,

    Do the contents of the HTML file you download give you a hint as to what is going wrong?

    It's been a while since I worked with Mechanize, so someone else might have a quicker solution handy, but my first thought was to use Wireshark to record a normal, successful session from the browser and compare that to what Mechanize is doing. Perhaps there is a redirect happening that Mechanize isn't dealing with, or the server has a mechanism in place to detect automated downloads, or some header isn't getting set the right way, or something else...

    Update: Actually, the AM is probably right, why are you switching from WWW::Mechanize to LWP::Simple? You lose any cookies or referrers that logging in with Mechanize gains you.

    Regards,
    -- Hauke D

      Losing the cookies. That's probably why the downloaded page is the logout page! I could not figure out why. Thank you, I will try Mechanize and report back.

Re: LWP::Simple trouble.
by Anonymous Monk on May 16, 2016 at 20:12 UTC

    Any thoughts?

    stick with WWW::Mechanize, LWP::Simple is too simple

    Also, study the mechanize faq, use firefox+livehttpheaders/wireshark, figure out what headers you need to send , what cookie setting web bugs you need to load, what urls you need to access...

    there is no windows, just urls, no secret except trace the http

      Thank you guys! It works with:

      $mech -> get($downloadURI); $mech -> save_content($fileName);

      I thought LWP::Simple was the standard way to download stuff with perl. The problem really was the loss of the cookies.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (7)
As of 2024-04-16 18:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found