-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (29 loc) · 921 Bytes
/
index.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
const cheerio = require('cheerio');
const got = require('got');
let urls = [
'https://www.youtube.com/watch?v=f2rPHMSOYxc',
'https://www.youtube.com/watch?v=gdY9n0A1F-k',
'https://www.youtube.com/watch?v=GcT74izO5N8',
'https://www.youtube.com/watch?v=ZYWuFzs4BPA'
]
const removeInfo = (str) => {
let view_count = str.replace('visualizações', '');
return view_count.replace('.', '');
}
const getCount = (url) => {
got(url).then(response => {
let $ = cheerio.load(response.body);
if (typeof $('div[class=watch-view-count]')[0] === 'undefined')
getCount(url)
else {
let tag = removeInfo($('div[class=watch-view-count]')[0].children[0].data)
console.log(tag)
}
})
.catch(error => {
console.log(error);
});
}
urls.forEach(element => {
getCount(element)
})