var http = require('https'), cheerio = require('cheerio'), xlsx = require('node-xlsx');
var baseUrl = 'https://shanghai.anjuke.com/sale/'; var m = 'm7';
// 设置只爬取前10页的信息 for (var i = 1; i <= 10; i++) { startRequest(m, i); }
var dataArr = []; var data = [ // Excel表头信息 [ '所在区', '房型', '价格', '大小', '地址', '安居客网址链接', ] ];
function startRequest(m, p) { // 安居客二手房信息第一页:https://shanghai.anjuke.com/sale/m7-o5-p1/ var url = baseUrl + m + '-o5-p' + p + '/'; http.get(url, function (res) { var html = ''; res.setEncoding('utf-8');
res.on('data', function (chunk) { html += chunk; });
res.on('end', function () { var $ = cheerio.load(html);