简体   繁体   English

在内容html中出现问号``1''。

[英]Appear question mark �1��� in content html?

I'm using node to load html page from url. 我正在使用node从url加载html页面。 Here is my code: 这是我的代码:

request({
    url : url,
    timeout: 2000
}, function(error, response, html){
   console.log(html);
});

But when I run it appear strangle character 1 . 但是当我运行它时,它会出现勒死字符``1''。 I think this is not UTF-8. 我认为这不是UTF-8。 How can I fix it. 我该如何解决。

example url: http://news.zing.vn/Nhung-hinh-anh-giau-cam-xuc-o-vong-17-VLeague-post560640.html 示例网址: http//news.zing.vn/Nhung-hinh-anh-giau-cam-xuc-o-vong-17-VLeague-post560640.html

The issue is that the server is returning the responses in compressed format (gzip), even when you don't specifically ask for it through request-headers. 问题是,即使您没有通过请求标头特别要求,服务器也会以压缩格式(gzip)返回响应。

To fix, you can use the gzip option of request : 要解决此问题,可以使用requestgzip选项:

request({
    url     : url,
    gzip    : true,
    timeout : 2000
}, function(error, response, html){
   console.log(html);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM