您好,我希望能在命令提示符和HTML文件中打印结果。我在HTML中使用编码(cp1252)进行打印,但是在命令提示符中无法看到那些特殊字符,而是得到一些乱码值。例如,“£”被打印为“ú”。谢谢。
use strict;
use warnings;
use LWP::Simple;
use HTML::TreeBuilder::XPath;
use LWP::UserAgent;
my $competitor_declare='7shop';
my $xpath_declare='//strong';
my @urls = ("http://www.7dayshop.com/delivery-and-returns");
open HTML1, '>:encoding(cp1252)',"C:/Users/jeyakuma/Desktop/$competitor_declare.html";
open HTML, '>:encoding(cp1252)',"C:/Users/jeyakuma/Desktop/shipping project/database/$competitor_declare.html";
foreach my $url (@urls)
{
print "\n\nworking on $url\n\n";
my $ua = LWP::UserAgent->new( agent => "Mozilla/5.0" );
my $req = HTTP::Request->new( GET => "$url" );
my $res = $ua->request($req);
if ( $res->is_success )
{
print "Please wait while we create file \n\n";
my $xp = HTML::TreeBuilder::XPath->new_from_url($url);
my $node = $xp->findnodes_as_string("$xpath_declare") or print "couldn't find the node\n"; #give xpath
print HTML1 $node and print "Dump file is created please configure the same in xpathconfiguration.pl\n" and print HTML $node;
print $node;
}
else{
print "file creation failed\n";
}
}
在命令提示符中预期的输出
cost is - £1.99
当前结果
cost is - ú1.99
print "£££\n"
并查看屏幕上出现了什么。 - Borodin