-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmnet_crawling.js
More file actions
executable file
·101 lines (82 loc) · 2.51 KB
/
Copy pathmnet_crawling.js
File metadata and controls
executable file
·101 lines (82 loc) · 2.51 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const request = require('request');
const cheerio = require('cheerio');
const fs = require('fs');
const period = 3000;
const url = 'http://www.mnet.com/chart/TOP100';
const url2 = 'http://www.mnet.com/chart/TOP100?pNum=2';
setInterval( function(){
let jbAry = [];
let jbAry2 = [];
let jbAry3 = [];
let jbAry4 = [];
let jbAry5 = [];
let jbAry6 = [];
let arr = [];
request.get(url, function(err, response, body){
const $ = cheerio.load(body);
let postElements=$("a.MMLI_Song");
let postElements2=$("a.MMLIInfo_Artist");
let postElements3=$("a.MMLIInfo_Album");
postElements.each(function() {
let postTitle = $(this).text()+'\r\n';
jbAry += postTitle;
});
postElements2.each(function() {
let postTitle2 = $(this).text()+'\r\n';
jbAry2 += postTitle2;
});
postElements3.each(function() {
let postTitle3 = $(this).text()+'\r\n';
jbAry3 += postTitle3;
});
fs.writeFile('mnet_title.txt', jbAry, 'utf-8', function(error) {
console.log('writeFile completed');
check();
});
fs.writeFile('mnet_artist.txt', jbAry2, 'utf-8', function(error) {
console.log('writeFile completed');
check();
});
fs.writeFile('mnet_album.txt', jbAry3, 'utf-8', function(error) {
console.log('writeFile completed');
check();
});
});
const check = () =>{
arr.push(1);
if( arr.length ===3 ) return next();
else return;
}
//setTimeout(
const next = () =>{
request.get(url2, function(err, response, body){
var $2 = cheerio.load(body);
var postElements4=$2("a.MMLI_Song");
var postElements5=$2("a.MMLIInfo_Artist");
var postElements6=$2("a.MMLIInfo_Album");
postElements4.each(function() {
var postTitle4 = $2(this).text()+'\r\n';
jbAry4 += postTitle4;
});
postElements5.each(function() {
var postTitle5 = $2(this).text()+'\r\n';
jbAry5 += postTitle5;
});
postElements6.each(function() {
var postTitle6 = $2(this).text()+'\r\n';
jbAry6 += postTitle6;
});
fs.appendFile('mnet_title.txt', jbAry4, 'utf-8', function(error) {
console.log('writeFile2 completed');
});
fs.appendFile('mnet_artist.txt', jbAry5, 'utf-8', function(error) {
console.log('writeFile2 completed');
});
fs.appendFile('mnet_album.txt', jbAry6, 'utf-8', function(error) {
console.log('writeFile2 completed');
});
});
}
// }, 1000);
console.log('finish');
}, period);