-
Notifications
You must be signed in to change notification settings - Fork 0
/
cairn.js
51 lines (43 loc) · 2.23 KB
/
cairn.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
//need
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.cairn.info/resultats_recherche.php?searchTerm=${isbn}`);
await page.waitForSelector('#resultat-recherche > div > div:nth-child(2) > div > div.well.hidden-xs > div > ul > li:nth-child(1) > b');
const val = await page.evaluate(() => {
return document.querySelector('#resultat-recherche > div > div:nth-child(2) > div > div.well.hidden-xs > div > ul > li:nth-child(1) > b').textContent
})
console.log(val);
if (parseInt(val) === 0) {
console.log('No result');
await browser.close();
return;
}
await Promise.all([
await page.mouse.click(141,355),
page.waitForNavigation({
waitUntil: 'networkidle0',
}),
]);
const data = await page.evaluate(() => {
const title = document.querySelector('#numero > div > div > div > div.media-body > div.article-meta > ul:nth-child(1) > li').textContent
const Under_the_direction_of = document.querySelector('#numero > div > div > div > div.media-body > div.article-meta > ul:nth-child(2) > li').textContent.trim().slice(21);
const year = document.querySelector('#numero > div > div > div > div.media-body > div.article-meta > ul:nth-child(3) > li').textContent
const pages = document.querySelector('#numero > div > div > div > div.media-body > div.article-meta > ul:nth-child(4) > li:nth-child(2)').textContent;
const collection = document.querySelector('#numero > div > div > div > div.media-body > div.article-meta > ul:nth-child(4) > li:nth-child(3)').textContent;
const editor = document.querySelector('#numero > div > div > div > div.media-body > div.article-meta > ul:nth-child(4) > li:nth-child(4)').textContent;
const image = document.querySelector('#numero > div > div > div > div.media-left > img').src
return {
title,
Under_the_direction_of,
editor,
year,
pages,
collection,
image,
}
})
console.log(data);
})('9782706121371')