-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscraper.js
85 lines (75 loc) · 2.6 KB
/
scraper.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const puppeteer = require('puppeteer');
const csv = require('csv-parser');
const fs = require('fs');
const results = [];
/*
fs.createReadStream('data.csv')
.pipe(csv({
separator: '\t'
})
)
.on('data', (data) => results.push(data))
.on('end', () => {
console.log(results);
// [
// { NAME: 'Daffy Duck', AGE: '24' },
// { NAME: 'Bugs Bunny', AGE: '22' }
// ]
});
*/
const getScreenshot = async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.setExtraHTTPHeaders({
'Accept': 'application/json, text/plain, */*',
'Authorization': `Bearer 8qdu140mj28acpo2ikko4vfabd0noor4c8q3pnpk`
});
await page.goto('https://societeinfo.com/app/recherche/societe/353381981');
const selector = "#phone";
// const email = "email";
/*try {
await page.waitForSelector(selector);
const textContent = await page.evaluate(() =>
document.querySelector(selector).textContent
);
console.log('Phone number = ' + textContent);
} catch (error) {
console.log("The element didn't appear. " + error)
}*/
await page.screenshot({ path: "screenshot.png" });
await browser.close()
};
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto('https://societeinfo.com/app/recherche/societe/316265016');
const loginButton = "div.login > p";
try {
await page.waitForSelector(loginButton);
await page.click(loginButton);
} catch (e) {
console.log(`ERROR LoginButton ------- ${e} --------`);
}
try {
await page.waitFor('#mat-input-3');
await page.type('#mat-input-3', '[email protected]');
await page.waitFor('#mat-input-4');
await page.type('#mat-input-4', 'Azerty01');
await page.click('app-modal-login > div.modal-login.tac > form > button');
} catch (e) {
console.log(`ERROR Login ------- ${e} --------`);
}
try {
await page.waitForSelector('#email');
if (await page.$('#email') !== null) {
const element = await page.$("#email");
const text = await (await element.getProperty('textContent')).jsonValue();
// Ici email récupéré du coup formatter un csv avec chaque pour que ce soit prêt à l'emploi
console.log("Voici l'email: " + text);
}
else
console.log('not found');
} catch (e) {
console.log(`ERROR Recupération Email ------- ${e} --------`);
}
})();