我正在尝试使用 Node/Express 和 Cheerio 构建一个基本的 parcer,但是当服务器运行正常时,我在浏览器中没有收到任何页面。这是 server.js 的代码:
var express = require('express');
var request = require('request');
var cheerio = require('cheerio');
var app = express();
app.engine('.html', require('ejs').__express);
app.engine('html', require('ejs').renderFile);
app.set('views', __dirname + '/views');
app.get('/main', function(req, res) {
url = 'http://tres-bien.com/new-arrivals/';
request(url, function(error, response, html) {
var title, price, image;
var tres_bien = [ { title : 'tres'}, { price : 'bien'} ];
var images = [];
if (!error) {
var $ = cheerio.load(html);
$(".grid-info").each(function() {
var data = $(this);
title = data.children().first().text().replace(/(\r\n|\n|\r|\t)/gm, "");
price = data.children().last().children().text().replace(/(\r\n|\n|\r|\t|\s)/gm, "");
});
$(".dropjaw img").each(function() {
image = this.attr('href');
});
}
});
});// APP GET
app.listen('8081')
exports = module.exports = app;
先感谢您。