-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpu.js
46 lines (39 loc) · 2.6 KB
/
cpu.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
// 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸
const puppeteer = require('puppeteer');
(async (isbn) => {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.setDefaultTimeout(30000000);
await page.goto('https://www.cpu.rnu.tn/index.php/shop/');
await page.type('#woocommerce_product_search-2 > div > form > p.search_field > input.search-field', isbn);
await Promise.all([
page.click('#woocommerce_product_search-2 > div > form > p.search_button > button'),
page.waitForNavigation({
waitUntil: 'networkidle0',
}),
]);
const data = await page.evaluate(() => {
const title = document.querySelector('#product-26177 > div > div.summary.entry-summary.cmsmasters_product_right_column > div.cmsmasters_product_title_wrap > h1').textContent;
const price = document.querySelector('#product-26177 > div > div.summary.entry-summary.cmsmasters_product_right_column > div.cmsmasters_product_title_wrap > p > span').textContent;
// const author = document.querySelector('#product-26177 > div > div.summary.entry-summary.cmsmasters_product_right_column > div.cmsmasters_product_content > div > p:nth-child(2)').textContent;
const ISBN = document.querySelector('#product-26177 > div > div.summary.entry-summary.cmsmasters_product_right_column > div.cmsmasters_product_content > div > p:nth-child(3)').textContent;
const year = document.querySelector('#product-26177 > div > div.summary.entry-summary.cmsmasters_product_right_column > div.cmsmasters_product_content > div > p:nth-child(4)').textContent;
const pages = document.querySelector('#product-26177 > div > div.summary.entry-summary.cmsmasters_product_right_column > div.cmsmasters_product_content > div > p:nth-child(5)').textContent;
const format = document.querySelector('#product-26177 > div > div.summary.entry-summary.cmsmasters_product_right_column > div.cmsmasters_product_content > div > p:nth-child(6)').textContent;
const image = document.querySelector('#product-26177 > div > div.cmsmasters_product_left_column > div > div > a > img').src
const pageLink = window.location.href;
return {
title,
price,
// author,
ISBN,
year,
pages,
format,
image,
pageLink
}
})
await browser.close();
console.log(data);
})('978-9938-46-081-0')