const PORT = 3031;
const http = require('http');
const url = require('url');
const path = require('path');
// 获取时间
var startTime = new Date().getTime();
var server = http.createServer(s);
function s(req, res) {
res.setHeader("Access-Control-Allow-Origin", "*");
var pathname = url.parse(req.url).pathname;
var arg = url.parse(req.url, true).query;
if (pathname == "/s") {
var html = "";
var n = 0;
var baiduUrl = "
http://m.baidu.com/s?wd=" + (arg.wd ? arg.wd : arg.word);
console.log(baiduUrl);
http.get(encodeURI(baiduUrl), function (response) {
response.on("data", function (d) {
// console.log("==> ", d);
console.log(n++)
html += d;
})
response.on("end", function () {
res.write(html);
res.end();
})
})
}
};
server.listen(PORT);
console.log("Server runing at port: " + PORT + ".");