简体   繁体   中英

how can i download file using click method using perl?

I am trying to download xls file from website http://www.ncdex.com/MarketDataAction_bhavCopy.action

using Mechanize module click method, but it gives error like :

Error POSTing http://www.ncdex.com/MarketDataAction_bhavCopySubmit.action : Not Found at click_method.pl line 6.

Here is my code:

use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
my $url = 'http://www.ncdex.com/MarketDataAction_bhavCopy.action';
$mech->get( $url );
$mech->submit_form(
                fields      => {
                        'dateSelected' => '13/03/2017',
                }
        );
$mech->click_button(
                name => "buttonType",
                id => "buttonType",
                value => "xls Format",
                type => "submit"
        );

print $mech->content();

I want to download xls file from this website for date 13/03/2017 or any other date

Directly hit the url as below and write data to a .xls file

use WWW::Mechanize;
my $mech = WWW::Mechanize->new(autocheck => 0);
$mech->get("http://www.ncdex.com/MarketDataAction_bhavCopySubmit.action?bhavTitle=bhav&dateSelected=13%2F03%2F2017&buttonType=xls+Format");
my $data = $mech->content;
print $data;

You can check the code by running it and redirecting output to .xls file Eg:- perl test.pl > output.xls

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM