-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
62 lines (46 loc) · 1.52 KB
/
app.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
var express=require("express");
var superagent = require('superagent');
var cheerio = require('cheerio');
var app=express();
var jdUrl = 'http://www.jd.com';
superagent.get(jdUrl).end(function(err,sres){
if (err) {
return console.error(err);
}
var $=cheerio.load(sres.text);
var data=[];
$("#nav-2014 .dd .dorpdown-layer .item-sub").each(function(index,element){
var head=[];
var body=[];
var top=[];
var bottom=[];
var a=$(element).find(".item-channels a")
a.each(function(index,ele){
head.push(ele.innerText.replace(">",""));
})
var b=$(element).find(".subitems dl");
b.each(function(index,ele){
var bold = '';
var normal =[]
if(!$(ele).find("dt a").html()){
bold =$(ele).find("dt a").html();
}else{
bold=$(ele).find("dt a").html().replace("<i>></i>","")
}
$(ele).find("dd a").each(function(index,el){
normal.push($(el).html());
})
body.push({bold:bold,normal:normal});
})
var c=$(element).find(".item-brands img");
c.each(function(index,ele){
top.push($(ele).attr("src"));
});
var d=$(element).find(".item-promotions img");
d.each(function(index,ele){
bottom.push($(ele).attr("src"));
});
data.push({content:{head:head,body:body,top:top,bottom:bottom}});
})
console.log(JSON.stringify({data:data}));
})