输入文本:abc™Blue TestMix,200 x20 rxns,2ml(2x1ml)
使用此联机工具验证编码和解码的输出:http://www.web2generators.com/html-based-tools/online-html-entities-encoder-and-decoder该网站返回的产出如下:
Decode Text
ABC™ Blue<sup>®</sup> Testmix, 200 x 20 µl rxns, 2 ml (2 x 1 ml)
Encode Text
ABC™ Blue<sup>®</sup> Testmix, 200 x 20 µl rxns, 2 ml (2 x 1 ml)
我编写了Perl和Python代码,试图查看是否可以获得相同的输出:
Python代码
from HTMLParser import HTMLParser
try:
from html import escape # python 3.x
except ImportError:
from cgi import escape # python 2.x
def htmldecode(s):
h = HTMLParser()
return h.unescape(s)
text = "ABC™ Blue<sup>®</sup> Testmix, 200 x 20 µl rxns, 2 ml (2 x 1 ml)"
print (htmldecode(text))
print (escape(htmldecode(text)))
Python输出的编码文本:
ABC™ Blue<sup>®</sup> Testmix, 200 x 20 µl rxns, 2 ml (2 x 1 ml)
也尝试过Perl代码
use HTML::Entities;
my $input = "ABC™ Blue<sup>®</sup> Testmix, 200 x 20 µl rxns, 2 ml (2 x 1 ml)";
print encode_entities($input), "\n"
但是,输出是
ABC™ Blue<sup>®</sup> Testmix, 200 x 20 µl rxns, 2 ml (2 x 1 ml)
返回的输出不匹配,我做错了什么?http://www.web2generators.com/html-based-tools/online-html-entities-encoder-and-decoder
发布于 2018-08-09 16:35:24
加上
use utf8;
脚本开始附近的某个地方(最好的地方就在后面)use strict;
和use warnings;
)
https://stackoverflow.com/questions/-100008775
复制相似问题