[英]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.