-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrap.js
62 lines (48 loc) · 1.09 KB
/
scrap.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
'use strict'
const request = require('request');
const cheerio = require('cheerio');
const fs = require('fs')
const cities = [
"bialystok",
"gdansk",
"katowice",
"krakow",
"krosno",
"lublin",
"lodz",
"olsztyn",
"pila",
"poznan",
"radom",
"szczecin",
"szczecinek",
"torun",
"warszawa",
"wroclaw",
"zielonagora"
]
Promise.all(cities.map(city => {
return new Promise((resolve, reject) => {
const address = "http://www." + city + ".lasy.gov.pl/nadlesnictwa"
request(address, (err, response, body) => {
if(err) {
reject(err)
return
}
const $ = cheerio.load(body)
const mails = []
$("body").find(".email a[href^='mailto:']").each((i,a) => {
mails.push($(a).attr("href").replace('mailto:', ''))
})
resolve(mails)
})
})
})).then((values) => {
const mails = values.reduce((p,c) => p.concat(c), [])
console.log("AMOUNT", mails.length);
fs.writeFileSync("./mails.txt", mails.join(" "))
}).catch(err => {
console.log('----------------')
console.log(err)
console.log('----------------')
})