Download files with Perl

后端 未结 2 1636
南笙
南笙 2021-01-15 16:23

I have updated my code to look like this. When I run it though it says it cannot find the specified link. Also what is a good way to test that it is indeed connecting to the

相关标签:
2条回答
  • 2021-01-15 17:07

    As stated in a comment in your other question: here

    You can use the same method to retrieve .csv files as .html, or any other text-based file for the matter.

    #!/usr/bin/perl -w
    use strict;
    use LWP::Simple;
    
    my $csv = get("http://www.spc.noaa.gov/climo/reports/last3hours_hail.csv")
               or die "Could not fetch NWS CSV page.";
    

    To login, you may need to use WWW::Mechanize to fill out the webform (look at $mech->get(), $mech->submit_form(), and $mech->follow_link())

    0 讨论(0)
  • 2021-01-15 17:08

    Basically, you need to fetch the page, parse it to get the URL, and then download the file.

    Personally, I'd use HTML::TreeBuilder::XPath, write a quick XPath expression to go straight to the correct href attribute node, and then plug that into LWP.

    use HTML::TreeBuilder::XPath;
    my $tree = HTML::TreeBuilder::XPath->new;
    $tree->parse({put page content here});
    foreach($tree->findnodes({put xpath expression here}){
        {download the file}
    }
    
    0 讨论(0)
提交回复
热议问题