[英]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 我正在尝试从网站http://www.ncdex.com/MarketDataAction_bhavCopy.action下载xls文件
using Mechanize module click method, but it gives error like : 使用Mechanize模块的click方法,但是会出现如下错误:
Error POSTing http://www.ncdex.com/MarketDataAction_bhavCopySubmit.action : Not Found at click_method.pl line 6. 错误发布POST http://www.ncdex.com/MarketDataAction_bhavCopySubmit.action :在click_method.pl第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 我想从该网站下载日期为13/03/2017或任何其他日期的xls文件
Directly hit the url as below and write data to a .xls file 如下所示直接命中url并将数据写入.xls文件
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 您可以通过运行代码并将输出重定向到.xls文件来检查代码,例如:-perl test.pl> output.xls
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.