Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 915513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:54:00+00:00 2026-05-15T17:54:00+00:00

I am trying to download a file from a site using perl. I chose

  • 0

I am trying to download a file from a site using perl. I chose not to use wget so that I can learn how to do it this way. I am not sure if my page is not connecting or if something is wrong in my syntax somewhere. Also what is the best way to check if you are getting a connection to the page.

#!/usr/bin/perl -w
use strict;
use LWP;
use WWW::Mechanize;

my $mech = WWW::Mechanize->new();
$mech->credentials( '********' , '********'); # if you do need to supply server and realms use credentials like in [LWP doc][2]
$mech->get('http://datawww2.wxc.com/kml/echo/MESH_Max_180min/');
$mech->success();
if (!$mech->success()) {
    print "cannot connect to page\n";
    exit;
}
$mech->follow_link( n => 8);
$mech->save_content('C:/Users/********/Desktop/');
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:54:01+00:00Added an answer on May 15, 2026 at 5:54 pm

    I’m sorry but almost everything is wrong.

    • You use a mix of LWP::UserAgent and WWW::Mechanize in a wrong way. You can’t do $mech->follow_link() if you use $browser->get() as you mix function from 2 module. $mech don’t know that you did a request.
    • Arguments to credentials are not good, see the doc

    You more probably want to do something like this:

    use WWW::Mechanize;
    my $mech = WWW::Mechanize->new();
    
    $mech->credentials( '************' , '*************'); # if you do need to supply server and realms use credentials like in LWP doc
    $mech->get('http://datawww2.wxc.com/kml/echo/MESH_Max_180min/');
    $mech->follow_link( n => 8);
    

    You can check result of get() and follow_link() by checking $mech->success() result
    if (!$mech->success()) { warn "error"; ... }
    After follow->link, data is available using $mech->content(), if you want to save it in a file use $mech->save_content('/path/to/a/file')

    A full code could be :

    use strict;
    use WWW::Mechanize;
    my $mech = WWW::Mechanize->new();
    
    $mech->credentials( '************' , '*************'); #
    $mech->get('http://datawww2.wxc.com/kml/echo/MESH_Max_180min/');
    die "Error: failled to load the web page" if (!$mech->success());
    $mech->follow_link( n => 8);
    die "Error: failled to download content" if (!$mech->success());
    $mech->save_content('/tmp/mydownloadedfile')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use Python to download a voice file (mp3) from this site:
On Ubuntu, I am trying to download a file (from a script) using wget.
I'm trying to download an HTML file from a site. I'm using the following
I am trying to download Xcode from the Apple Developer site using just wget
I have a site, from which you can download an HTML file. This HTML
I'm trying to download a zip file (tl_2008_01001_edges.zip) from an ftp census site using
I am trying to download a file from a website using python and mechanize.
i'm trying to download .zip file from bluehost server to my computer. Like this
I'm trying to download the XLS file from this page: http://www.nordpoolspot.com/Market-data1/Elspot/Area-Prices/ALL1/Hourly/ (click on Export
I am trying to implement an Asynchronous file download from a web server using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.