Is there a way to set connection timeout of XML::LibXML->load_html( location => $url)

137 Views Asked by At

I am on a very bad network. I would like to adjust the connnection timeout of the XML::LibXML Is there a way to do ? or I need to load html with LWP first ?

my $doc = XML::LibXML->load_html( location => $url, recover => 2 );
1

There are 1 best solutions below

0
hoffmeister On

Personally, I would use 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();