gpt4 book ai didi

javascript - PhantomJS 将字符变成坏数据

转载 作者:行者123 更新时间:2023-11-28 04:44:11 25 4
gpt4 key购买 nike

我正在 phantomjs 中运行 js 文件

var settings = {mode: 'w', charset: 'UTF-8'};
page.open(path, settings, function (status) {
if (status !== "success") {
console.log("Unable to access network");
} else {
page.evaluate(function() {
window.console.log = function(msg) { alert(msg) };
var $p = document.querySelectorAll('.my-class')[0];
var html = $p.innerHTML;
return html;
});
}
});

数据看起来像

<div class="my-class">Power, speed, style —&nbsp;James Bond’s 10&nbsp;greatest drives</div>

但是从 phantomJS 返回的 html 是

Power, speed, style ΓÇö James BondΓÇÖs 10 greatest drives

我的页面有

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

在头脑中。

最佳答案

尝试编码参数。如果 UTF8 不起作用,请尝试 UTF-8

var settings = {mode: 'w', charset: 'UTF-8', encoding: 'UTF8'};

关于javascript - PhantomJS 将字符变成坏数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43530736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com