用request写了一个爬图片的爬虫
request(imgUrl, function(err, res, body) { if(!err && res.statusCode == 200) { console.log(body); } })
爬下来的body全是乱码,WTF???
于是我找到了这个:
iconv-lite:解决爬取gb2312网页出现乱码
const iconv = require("iconv-lite"); request({ encoding: null, url: imgUrl }, function(err, res, body) { if(!err && res.statusCode == 200) { let html = iconv.decode(body, "gb2312"); //console.log(html); } })
yes!问题解决