-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (36 loc) · 1.42 KB
/
index.js
File metadata and controls
39 lines (36 loc) · 1.42 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
const axios = require('axios');
const cheerio = require('cheerio');
async function parseDriversData(link) {
return new Promise(async (resolve) => {
const data = await axios(link);
const $ = cheerio.load(data.data);
let scripts = $('script:not([src])');
for (let i = 0; i < scripts.length; ++i) {
if (scripts[i].children[0].data.includes('window.serverParams')) {
let serverParams = scripts[i].children[0].data;
let driverInfosPart = serverParams.substring(serverParams.indexOf('driver_infos'));
driverInfosPart = driverInfosPart.substring(0, driverInfosPart.indexOf('\n') - 1);
let driversInfo = driverInfosPart.substring(driverInfosPart.indexOf('{'));
let drivers = JSON.parse(driversInfo);
let result = {};
for (let driverId in drivers) {
result[drivers[driverId].phone] = {
'id': driverId,
'name': drivers[driverId].name
};
}
resolve(result);
}
}
resolve(null);
});
}
(async () => {
if (process.argv.length !== 3) {
console.log("Can not get link param from command line arguments");
return;
}
const link = process.argv[2];
const drivers = await parseDriversData(link);
console.log(drivers);
})();