-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.js
executable file
·81 lines (65 loc) · 2.14 KB
/
Main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env node
/**
* Created with JetBrains WebStorm.
* User: eignil
* Date: 14-7-5
* Time: 下午2:37
* To change this template use File | Settings | File Templates.
*/
var productFetcher = require("./ProductFetcher").ProductFetcher;
var etaoFetcher = require("./EtaoFetcher").EtaoFetcher;
var mongo = require("./MongoOperator").MongoOperator;
var asyncr=require("async");
var fs = require("fs");
var page_url ="http://list.jd.com/list.html?cat=9987,653,655";
var db_url="mongodb://localhost:27017/";
var db_name="goods_jd";
var coll_name = "phone";
asyncr.series([
function(callback){
mongo.Init(db_url,db_name,coll_name,function(coll){
console.log("DB init finished!") ;
callback(null);
});
},
function(callback){
asyncr.whilst(
function(){
if(page_url){
return true;
}else{
return false;
}
},
function(callback){
productFetcher.JDFetchProductItemList(page_url,function(status,nextPage,itemUrls){
if(status==="fail"){
callback(null);
}
console.log(nextPage,itemUrls);
page_url = nextPage;
itemUrls.forEach(function(ele){
etaoFetcher.GetProductInfoFromEtao(ele,function(data){
if(data.Item){
mongo.InsertDB(data.Item,function(err,res){
});
}else{
console.log("Wrong data!",data.Item);
}
});
});
callback(null);
});
},
function(err){
console.log("page_url is null");
}
);
},
function(callback){
console.log("Finished");
callback(null);
}
]);
//page_data=fs.readFileSync("exp/phone_list.html",{encoding:"utf-8"});
//fs.writeFileSync("exp/phone_list_nodes.txt",page_data);