request抓取google的首页正常,抓取google搜索结果页就乱码,为什么呢?!
发布于 10 年前 作者 mscrm 5204 次浏览 最后一次编辑是 8 年前

代码如下:


var request = require('request');
var cheerio = require('cheerio');
var http = require('http');


http.createServer(function (req, res) {
	request("http://www.google.com",function(error,response,body){
		if(!error && response.statusCode == 200){
			res.writeHead(200, {'Content-Type': 'text/html'}); 
			res.end(body);
		}
	})


}).listen(8080, "127.0.0.1");


4 回复

这个问题根本不是问题,你的浏览器使用的编码与源编码一样吗?

留意一下gzip, 不知道request有么有处理这个环节

浏览器是用utf8,抓取返回的html也是charset=utf8。但是就是搜索列表页面中文乱码。首页的中文不乱码。

已经在options里增加了encoding : null

回到顶部