好吧,我明白了。
use XML::LibXML;
use strict;
use warnings q(all);
my $dom = XML::LibXML->load_html( location => pop );
for ( $dom->findnodes("//a") ) {
my $content = $_->textContent;
my $t = $dom->createTextNode($content);
$_->replaceNode($t);
}
for ( $dom->findnodes("//img") ) {
my $alt = $_->getAttribute("alt");
my $t = $dom->createTextNode($alt);
$_->replaceNode($t);
}
print $dom->toString();