使用 WWW:Mechanize 登录并下载 perl 脚本中的文件,但无法进入实际页面内容

Used WWW:Mechanize to login and download a file in perl script but cannot get into the actual page content

我正在尝试使用 Perl 脚本中的 Mechanize 登录站点。它确实登录到索引页面,但我尝试获取存在文件超链接的页面内容然后我没有登录我假设在查看页面内容后

其次,我们如何从文件的间接超链接下载文件,该超链接指向某个动作,然后下载文件。请指导,因为对于这个特定的用例没有太多帮助

下面是我的代码

use WWW::Mechanize;
use LWP;

my $username = 'user'; 
my $password = 'pass';

my $mech = WWW::Mechanize->new();
$mech -> cookie_jar(HTTP::Cookies->new());
$mech -> get('some_website/index.html?#');
$mech -> form_name('form');
$mech -> field ('user' => $username);
$mech -> field ('password' => $password);
$mech->submit();
$mech -> get('actual_page_address_with_file_hyperlinks?adfgenDispatchAction=examine&idProgressivo=0&idFlusso=4200212');
#print $mech-> content();

$mech->save_content("result.html");

my @links = $mech->links();
for my $link ( @links ) {

    #if(index($link->text,"Scarica")!= -1)
    #{
    printf "%s, %s\n", $link->text, $link->url;
    #}
}

;

由于网站使用的是 CSRF 令牌,并且登录页面中没有定义隐藏标签来存储 CSRF 令牌,因此脚本中的令牌生成没有帮助。

我使用了 WWW::Selenium,我能够登录该站点并下载文件。问题已解决 –