use*_*649 5 perl encoding mechanize
我正在尝试使用Mechanize开发PERL程序,这将允许我从我的网站上重新发布其他网站上的内容.但我在编码方面遇到了一些问题:
我的网站使用UTF-8编码,另一个网站使用ISO-8859-15编码.以下是我网站上的数据样本以及其他网站上公布的结果:
10 M€d'encours/10 M?d?encours
这是我的PERL计划:
#!/usr/bin/perl
use utf8;
use strict;
use warnings;
use WWW::Mechanize;
use HTML::TreeBuilder;
use HTML::TreeBuilder::XPath;
my $mech = WWW::Mechanize->new(
stack_depth => 0,
timeout => 10,
);
$mech->get("RecoveredDataFromMyWebsiteUrl");
my $tree = HTML::TreeBuilder::XPath->new_from_content($mech->content);
my $data = $tree->findvalue('/html/body//div[@id="content"]');
$data = Encode::encode("iso-8859-15",$data);
$mech->get("OtherWebsiteFormularUrl");
$mech->form_name("formular")->accept_charset('iso-8859-15');# Form Post Emploi
$mech->set_fields(
content => $data
);
$mech->submit;
open FIC,">output.html"
or die "E/S : $!\n";
my $out = select(FIC5);
print $mech->content;
Run Code Online (Sandbox Code Playgroud)
小智 1
我会改变一些关于如何抓取网站的事情,但也许在尝试在编码 utf8 时写入文件时尝试这样做:
my $out_file = 'output.html';
open ( my $fh, ">:encoding(utf8)", $out_file) or die;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
229 次 |
| 最近记录: |