我正在使用node + jsdom抓取html文档。但同样的错误信息一次又一次地重复。此外,错误消息不规则地出现,所以我无法确定问题是什么。谁能告诉我为什么会这样呢?
var async = require("async"),
jsdom = require("jsdom"),
jsonfile = require("jsonfile"),
scanf = require("scanf");
console.log("Input a json file name that includes uri codes");
var json_1st = scanf('%s');
var schCD = require('./json/'+ json_1st +'.json');
console.log("What kind of file?\n[1] A\n[2] B\n[3] C");
var selec_sch = scanf('%d');
if (selec_sch == 1){
selec_sch = 9;
}else if(selec_sch == 2 ){
selec_sch = 6;
}else if(selec_sch ==3 ){
selec_sch = 12;
}else{console.log('Wrong Input. terminating process.');
process.exit(1);}
var times = 0;
//async start
async.mapSeries(schCD, function(item, callback){
//target page info
jsdom.env(
"http://www.schoolinfo.go.kr/ei/pp/Pneipp_b01_s0p.do?HG_NM=%B0%A5%BF%F8%C3%CA%B5%EE%C7%D0%B1%B3&HG_CD=" + item.HG_CD + "&GS_BURYU_CD=JG010&GS_HANGMOK_CD=01&JG_BURYU_CD=JG030&JG_HANGMOK_CD=62&JG_GUBUN=1&GS_HANGMOK_NO=3-1-1&GS_HANGMOK_NM=%C7%D0%B1%B3+%C7%F6%C8%B2&JG_YEAR2=2015&GS_TYPE=Y&JG_YEAR=2015&SORT=BR",
["http://code.jquery.com/jquery.min.js"],
function(err, window){
if(err) throw err;
var $ = window.$;
var tObj= $('table.TableType3 tbody tr:first-child td');
console.log( "Name : " + item.HG_NM); // verifying stage
console.log( "Code : " + item.HG_CD);
var completeObj = {
"HG_name" : item.HG_NM,
"HG_CD" : item.HG_CD
};
if(tObj[0]) { // dealing with exception
completeObj.Gyowon = tObj[selec_sch].innerHTML;
switch(selec_sch){
case 9 :
completeObj.G1 = tObj[0].innerHTML;
completeObj.G2 = tObj[1].innerHTML;
completeObj.G3 = tObj[2].innerHTML;
completeObj.G4 = tObj[3].innerHTML;
completeObj.G5 = tObj[4].innerHTML;
completeObj.G6 = tObj[5].innerHTML;
completeObj.sp = tObj[7].innerHTML;
case 6 :
completeObj.G1 = tObj[0].innerHTML;
completeObj.G2 = tObj[1].innerHTML;
completeObj.G3 = tObj[2].innerHTML;
completeObj.sp = tObj[4].innerHTML;
case 12 :
var tObj = window.$('table.TableType3 tbody tr:eq(-2) td');
completeObj.G1 = tObj[0].innerHTML;
completeObj.G2 = tObj[2].innerHTML;
completeObj.G3 = tObj[4].innerHTML;
completeObj.sp = tObj[6].innerHTML;
}
console.log( "Gyowon : " + completeObj.Gyowon);
console.log(completeObj);
if(completeObj.Gyowon) {console.log('---Loading Success---'); }
}else{
console.log('---No data---');
}
// showing progress
times++;
var procc = times/schCD.length*100;
console.log('progress : ' + times + '/' + schCD.length + '(' + procc.toFixed(1) + '%)\n' );;
callback(null, completeObj);
});
}, function (err, result){
console.log(result);
console.log("parsing Ended. Writing son");
jsonfile.writeFile('./completeDB/'+json_1st+'_gyoDB.json', result, {spaces: 4}, function(err){
if(err) console.log(err);
});
console.log('done');
err && console.log(err);
});
这是错误消息:
TypeError: $ is not a function
at Object.done (/Users/Snark/Dev/parsing/parsing_gyo.js:35:15)
at /Users/Snark/node_modules/jsdom/lib/jsdom.js:271:18
at doNTCallback0 (node.js:419:9)
at process._tickCallback (node.js:348:13)