繁体   English   中英

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

[英]Node js console.log is not showing anything

我正在尝试使用节点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不能按预期工作,否则它将工作,并且问题出在其他方面!

希望这会帮助你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM