当我像这样转换我的$url时,我能获得一些东西:$url = URI-> new($url)?
#!/usr/bin/env perl use warnings; use strict; use 5.012; use URI; use XML::LibXML; my $url = 'https://stackoverflow.com/'; $url = URI->new( $url ); my $doc = XML::LibXML->load_html( location => $url,recover => 2 ); my @nodes = $doc->getElementsByTagName( 'a' ); say scalar @nodes;
解决方法
URI module constructor会为您清理URI – 例如正确地转义URI构造无效的字符(参见
URI::Escape).