-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
68 lines (53 loc) · 1.45 KB
/
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
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
const fetch = require('node-fetch')
const cheerio = require('cheerio')
const args = require('node-args');
const countryCode = args.country || 'ua'
const pageFrom = args.pageFrom || 1
const pageTo = args.pageTo || 10
const timeout = args.timeout || 100
const filterBank = args.filterBankName || false
let currentPageNum = pageFrom
let totalCount = 0
const getUrl = () => `http://mastercvv.ru/bin/lookup/creditcard/page_${currentPageNum}.html`
const fetchPage = (url) => fetch(url).then(r => r.text())
const showFormatData = (tr) => {
const $ = cheerio.load(tr)
const arr = []
const binBank = $('td').eq(0).text()
const bankName = $('td').eq(1).text()
if( filterBank && filterBank != bankName ) {
return
}
return `${binBank} | ${bankName}`
}
const parseResponse = (r) => {
let $ = cheerio.load(r)
let stringData = null
$('tr').map((id, item) => {
const countryFromPic = ($(item).find('img').attr('src') + "").slice(-6, -4)
if( countryFromPic === countryCode ) {
stringData = showFormatData($(item).html())
}
})
return stringData
}
(function getData() {
if( currentPageNum < pageTo ) {
fetchPage(getUrl()).then(r => {
const data = parseResponse(r)
if(data) {
console.log(data)
totalCount++
}
}).catch(e => { console.log(`Error: ${e.code}, ${getUrl()}`) })
setTimeout(() => {
currentPageNum++
getData()
}, timeout)
}
else {
setTimeout(() => {
console.log(`\nTotal count: `, totalCount)
}, timeout * 50)
}
})()