Perl Mechanize follow_链接失败

Perl Mechanize follow_链接失败,perl,automation,web-scraping,mechanize,Perl,Automation,Web Scraping,Mechanize,我正在尝试使用以下代码登录到一个站点 my $mech = WWW::Mechanize->new(autosave=>1); $mech->cookie_jar(HTTP::Cookies->new()); $mech->get($url); $mech->follow_link( text => 'Sign In'); $mech->click(); $mech->field(UserName => "$username"); $m

我正在尝试使用以下代码登录到一个站点

my $mech = WWW::Mechanize->new(autosave=>1);
$mech->cookie_jar(HTTP::Cookies->new());
$mech->get($url);
$mech->follow_link( text => 'Sign In');
$mech->click();
$mech->field(UserName => "$username");
$mech->field(Password => "$password");
$mech->submit();
但是在follow_链接期间,href包含两个前斜杠,例如(
//test/sso login
),因此follow_链接将其视为整个URL,失败如下

Error GETing http://test/sso-login: Can't connect to test:80 (Bad hostname)

我无法更改href,因为这是我的控制范围。是否有办法克服此问题,并使其采用附加此href的完整URL。

当然。您可以在调用
follow\u link()
之前修改Mech正在查看的HTML:


有关详细信息,请参阅。在该页面上搜索“更新html”。

当然。您可以在调用
follow\u link()
之前修改Mech正在查看的HTML:

有关详细信息,请参阅。在该页面上搜索“更新html”

my $html = $mech->content;
$html =~ s[//test/sso-login][http://example.com/test/sso-login]isg;
$mech->update_html( $html );