-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuppet.js
55 lines (48 loc) · 1.62 KB
/
puppet.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
const puppeteer = require('puppeteer');
let browserWSEndpoint = null;
async function runTest() {
if (!browserWSEndpoint) {
const browser = await puppeteer.launch({
headless: 'new',
timeout: 100000
});
browserWSEndpoint = await browser.wsEndpoint();
}
const browser = await puppeteer.connect({browserWSEndpoint});
const page = await browser.newPage();
const url = 'https://next.obudget.org/s?q=%D7%9B%D7%9C%D7%91%D7%AA&dd=budget&kind=all&fiscal-year=all';
await page.goto(url, {
waitUntil: 'networkidle2'
});
await new Promise(r => setTimeout(r, 500));
let items = await page.evaluate(() =>
[...document.querySelectorAll('search-result > .card')]
.map((item) => {
return {
rect: item.getBoundingClientRect(),
doc_id: item.getAttribute('data-doc-id')
};
})
.map((item) => {
return {
clip: {
x: item.rect.x,
y: item.rect.y,
width: item.rect.width,
height: item.rect.height
},
doc_id: item.doc_id
};
})
);
console.log('items', items.length);
const images = await Promise.all(items
.map((item) => page.screenshot({clip: item.clip, encoding: 'base64'}))
);
items = items.map((item, i) => {
return Object.assign({img: images[i]}, item);
});
console.log(items[0]);
browser.close();
}
runTest();