节点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)>表> tbody> tr> td>表> tbody> tr')。each(function(i,element){
json.push({} );
json [i] .range = $(this).text()。trim();
});
console.log(json);
请确保您的 console.log
可以正常工作,只需尝试一下:
控制台.log('starting'); //< -------------------------------------- -添加行
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); //< --------------------添加了
行
$('body> table:nth-child(1)> tbody> tr:nth-child(3)> td> table> tbody> tr> td :nth-child(2)>表> tbody> tr> td>表> tbody> tr')。each(function(i,element){
json.push({} );
json [i] .range = $(this).text()。trim();
});
console.log('json中的元素:'+ json.length); //< --------------添加了
控制台行。 log(json);
如果这在服务器端上不产生任何结果,那么是的,我们可以确认您的 console.log
不能按预期工作,否则它可以工作并且问题是由其他原因引起的! $ b
希望这会对您有所帮助。
I'm trying to scrap a webpage using node js.I think I've written the code and was able to run it without any errors but the problem is the console doesn't print anything no matter what I do.It is not showing any errors. What's the reason?
Here is the content that I want to scrap: 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);
To be sure that your console.log
work correctly just try it like that :
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);
If this don't produce anything on the server-side, so yes we can confirm that your console.log
don't work as expected, else it works and the problem come from other things !
Hope this will help you.
这篇关于节点js console.log没有显示任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!