Node js console.log没有显示任何内容

Node js console.log is not showing anything

本文关键字:显示 任何内 js console log Node      更新时间:2023-09-26

我正在尝试使用node js废弃网页。我想我已经编写了代码,并且能够在没有任何错误的情况下运行它,但问题是无论我做什么,控制台都不会打印任何内容。它没有显示任何错误。原因是什么?

这是我想要废弃的内容:https://paste.ee/r/b3yrn

var fs         = require('fs');
var request    = require('request');
var cheerio    = require('cheerio');
var htmlString = fs.readFileSync('scrap.html').toString();
var $          = cheerio.load(htmlString);
var json = [];
$('body > table:nth-child(1) > tbody > tr:nth-child(3) > td > table > tbody > tr > td:nth-child(2) > table > tbody > tr > td > table > tbody > tr').each(function(i, element) {
    json.push({});
    json[i].range = $(this).text().trim();
});

console.log(json);

要确保您的console.log正常工作,只需尝试这样:

console.log('starting');//<--------------------------------------- added line
var fs         = require('fs');
var request    = require('request');
var cheerio    = require('cheerio');
var htmlString = fs.readFileSync('scrap.html').toString();
var $          = cheerio.load(htmlString);
var json = [];
console.log('htmlString : ' + htmlString );//<-------------------- added line

$('body > table:nth-child(1) > tbody > tr:nth-child(3) > td > table > tbody > tr > td:nth-child(2) > table > tbody > tr > td > table > tbody > tr').each(function(i, element) {
    json.push({});
    json[i].range = $(this).text().trim();
});
console.log('Elements in json : ' + json.length);//<-------------- added line
console.log(json);

如果这在服务器端上没有产生任何东西,那么是的,我们可以确认您的console.log不像预期的那样工作,否则它可以工作,问题来自其他事情!