CNode

https 远程获取内容的 编码问题

问答
Ddingyong666发布于11 年前最后回复11 年前7 回复4169 浏览0 收藏

var https = require('https'); var punycode = require('punycode') https.get({ host: 'sp0.baidu.com', path: '/8aQDcjqpAAV3otqbppnN2DJv/api.php?query=202.194.101.150&co=&resource_id=6006' }, function(res) { res.on('data', function(d) { d.toString('utf8',0,d.length) });

}).on('error', function(e) { console.error(e.toString()); });

网页的 代码返回的 是个 gbk的编码 , res.on 返回的 是个 buffer 还不知道 是个上面 编码 ,utf8 转出来 中文乱码 ,求如何 解决,还是 必须 用 其他的 爬虫 模块

查看回复

回复 (7)

A
alsotang#1·11 年前

用 request 这个库,直接使用 https 模块太烦了

D
dingyong666#2·11 年前

不用了 ,明显是 百度的接口坑爹!!!换api了 。

D
dingyong666#3·11 年前
引用 alsotang用 request 这个库,直接使用 https 模块太烦了

@alsotang request 换个这个后 还是 乱码 !!百度真是坑爹 ,就不能把中文转一下码。。

M
magicdawn#4·11 年前

用 superagent 然后加一个 superagent-charset

.charset('gbk')

A
alsotang#5·11 年前
引用 magicdawn用 superagent 然后加一个 superagent charset .charset('gbk')

@magicdawn 用 superagentparse........

  1. superagentparse 可以获取 buffer
  2. superagentparse 用的是 superagent 原生的 parse 方法。。。

https://github.com/alsotang/superagentparse

K
klesh#7·11 年前

用 iconv-lite 转码

参与回复
登录后即可参与回复。登录