-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackoverflow.js
More file actions
69 lines (51 loc) · 1.83 KB
/
stackoverflow.js
File metadata and controls
69 lines (51 loc) · 1.83 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
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
69
const puppeteer = require('puppeteer');
const fs = require("fs");
// let data = require("./db/stack.json");
let inf = [];
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// await page.setViewport({
// width: 1440,
// height: 1072,
// deviceScaleFactor: 1,
// });
for(let i = 1; i <= 1000; i++){
await page.goto(`https://api.stackexchange.com/2.2/users?page=${i}&order=desc&sort=reputation&site=stackoverflow&key=U4DMV*8nvpm3EOpvf69Rxw((`);
let data = await page.evaluate(() => {
if(!!document.querySelector('pre') == false){
} else {
let text = JSON.parse(document.querySelector('pre').textContent);
let divs = text.items;
let datas = []
divs.forEach(div => {
let location = (div.location);
if(location == false || location == undefined){
} else{
location = location.toLowerCase()
if(location.includes('ukraine') || location.includes('kiev') || location.includes('киев') || location.includes('russia') || location.includes('киев') || location.includes('bilorus') || location.includes('kazakhstan') || location.includes('россия') || location.includes('moldova')){
let link = div.link;
// location.push
datas.push({link, location})
}
}
});
return datas
}
})
if(data != undefined){
if(data[0]){
inf.push(data);
}
}
}
console.log(inf)
// inf = JSON.parse(inf)
await browser.close();
fs.appendFile("./db/stack.json", JSON.stringify(inf), function (err) {
if (err) throw err;
console.log('Saved!');
});
console.log("insert")
})();
// https://api.stackexchange.com/2.2/users?page=103&order=desc&sort=reputation&site=stackoverflow