有没有一种方法可以设置XML :: LibXML-> load_html(location => $ url)的连接超时

时间:2020-06-29 05:42:53

标签: perl libxml2 xml-libxml

我的网络非常糟糕。我想调整XML :: LibXML的连接超时有办法吗?还是我需要先用LWP加载html?

mymap

1 个答案:

答案 0 :(得分:2)

我个人会使用Mojo::UserAgent

#!/usr/bin/env perl
use strict;
use warnings;

use  Mojo::UserAgent;
use XML::LibXML;

my $url = "https://www.w3schools.com/xml/cd_catalog.xml";
my $ua = Mojo::UserAgent->new();
$ua->max_redirects(0)->connect_timeout(3)->request_timeout(5);

my $xml = $ua->get( $url )->result->body;
my $doc = XML::LibXML->load_xml( string => $xml );


print $doc->toString();