-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.js
More file actions
46 lines (28 loc) · 1.05 KB
/
parse.js
File metadata and controls
46 lines (28 loc) · 1.05 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
const puppeteer = require('puppeteer');
const excel = require("excel4node");
const reader = require( 'xlsx' );
const file = reader.readFile('./Test.xlsx')
let scrape = async () => {
const browser = await puppeteer.launch({headless: false});
/// const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('http://pkf-thp.website-testing.ru');
const result = await page.evaluate(() => {
let data = [];
let elements = document.querySelectorAll('.cs-product-gallery__info-panel');
for (var element of elements){
let title = element.childNodes[1].innerText;
let price = element.childNodes[5].children[0].innerText;
data.push({title, price});
}
return data;
});
browser.close();
return result;
};
scrape().then((value) => {
console.log(value);
const ws = reader.utils.json_to_sheet(value)
reader.utils.book_append_sheet(file,ws,"Sheet1")
reader.writeFile(file,'./Test.xlsx')
});