跳到主要内容
CNode

request抓取google的首页正常,抓取google搜索结果页就乱码,为什么呢?!

社区
Mmscrm发布于 12 年前最后回复 12 年前
462260

代码如下:


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)

M
mscrm#412 年前
引用 fish留意一下gzip, 不知道request有么有处理这个环节

已经在options里增加了encoding : null

M
mscrm#312 年前
引用 chloe这个问题根本不是问题,你的浏览器使用的编码与源编码一样吗?

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

F
fish#212 年前

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

C
chloe#112 年前

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

参与回复

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