const http = require("http");
const cheerio = require("cheerio");
const iconv = require('iconv-lite');
const BufferHelper = require('bufferhelper');
var App = {
isDoing: 0,
concurrentCount: 0,
start: function () {
var _this = this;
var datas = [];
var opt = {
host: 'www.66ip.cn',
port: '80',
method: 'GET',//这里是发送的方法
path: 'http://www.dyjqd.com', //这里是访问的路径
}
http.get(opt, function (res) {
var bufferHelper = new BufferHelper();
res.on('data', function (chunk) {
bufferHelper.concat(chunk);
});
res.on('end', function () {
var html = iconv.decode(bufferHelper.toBuffer(), 'GBK');
console.log(html);
})
});
}
}
App.start();
运行后
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Not Found</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Not Found</h2>
<p>HTTP Error 404. The requested resource is not found.</p>
</BODY></HTML>
如果不采用代理
http.get('http://www.dyjqd.com', function (res)
直接是可以采集到内容,不知道哪里写错了,请求大神指导
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…