-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (36 loc) · 1.19 KB
/
index.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
require("dotenv").config();
const { error } = require('console');
const puppeteer = require('puppeteer');
async function scrapeEmail(email) {
try {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto('https://haveibeenpwned.com');
await page.type('#Account', email);
await Promise.all([
page.waitForNavigation(),
page.click('#searchPwnage'),
]);
const newcount = await page.evaluate(() => {
const pwnCount = document.querySelector("#pwnCount").innerText;
return pwnCount;
});
if (newcount.length === 91) {
console.log("Congratulations! Not Pawned");
} else {
console.log("Oh no, this email is pawned");
const pawnedSites = await page.evaluate(() => {
const sites = Array.from(document.querySelectorAll(".pwnedCompanyTitle"), element => element.innerText);
return sites;
});
console.log(pawnedSites);
}
await browser.close();
} catch (error) {
console.error('Error:', error);
return 'An error occurred while scraping the email.';
}
}
scrapeEmail(process.env.email).then(result => {
// console.log(result);
});