-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathproxyscraper.js
38 lines (34 loc) · 1.05 KB
/
proxyscraper.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
/* us-proxy.org scraper */
const fs = require('fs')
const axios = require('axios')
const cheerio = require('cheerio')
const UsProxy = ({ saveTo = `us-proxy-${new Date().getTime()}.txt`} = {}) => {
return new Promise(async(resolve, reject) => {
const options = {
headers: {
'User-Agent': 'googlebot'
}
}
var url = 'https://us-proxy.org/'
try {
var { data: html } = await axios(url)
$ = cheerio.load(html)
var proxy = $('textarea.form-control').text()
proxy = proxy.split('\n').splice(3).join('\n')
if (saveTo) {
fs.writeFileSync(saveTo, proxy)
resolve({
success: true,
saveTo
})
}
} catch ({ status }) {
reject({
message: `Error with status code ${status}`
})
}
})
}
// For testing
UsProxy().then(data => console.log(data)).catch(e => console.log(e))
module.exports = UsProxy