LanScraper/index.js

76 lines
2.4 KiB
JavaScript
Raw Normal View History

2022-02-27 04:18:11 +01:00
const puppeteer = require("puppeteer-extra");
const pluginStealth = require("puppeteer-extra-plugin-stealth");
const path = require("path");
const downloadPath = path.resolve("./Result");
const fs = require("fs");
const { URL } = require("./config");
puppeteer.use(pluginStealth());
(async () => {
var dateTime = require("node-datetime");
var dt = dateTime.create();
var formattedDate = dt.format("d-m-Y H:M:S");
console.log(
`Je démarre le programme ( Scrapper Dell ) by Lantium , ${formattedDate}`
);
var dir = __dirname + "/Result";
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, 0744);
}
const answer = process.argv.slice(2);
const browser = await puppeteer.launch({ headless: true });
const page1 = await browser.newPage();
await page1.setViewport({ width: 1920, height: 1080 });
await page1.goto(`${URL}`);
await page1.waitForSelector("#inpEntrySelection");
await page1.click("#inpEntrySelection");
await page1.keyboard.type(`${answer}`);
await page1.waitForSelector("#txtSearchEs");
await page1.click("#txtSearchEs");
await page1.waitForTimeout(5000);
await page1.waitForSelector("#quicklink-sysconfig");
await page1.click("#quicklink-sysconfig");
await page1.waitForTimeout(5000);
await page1.waitForSelector("#current-config-export");
await page1._client.send("Page.setDownloadBehavior", {
behavior: "allow",
downloadPath: downloadPath,
});
await page1.click("#current-config-export");
await page1.waitForTimeout(5000);
await browser.close();
const csv = require("csv-parser");
const results = [];
const parser = fs
.createReadStream(`${downloadPath}/${answer}.csv`)
.pipe(csv());
parser.on("data", (data) => results.push(data));
parser.on("end", () => {
console.log('Proc')
2022-02-27 04:18:11 +01:00
console.log(results.filter((record) => record.Description.includes("PRC")));
console.log('#############################################################');
console.log('Chassis')
console.log(results.filter((record) => record.Description.includes("CHAS")));
2022-02-28 00:47:55 +01:00
console.log('#############################################################');
console.log('Ram')
console.log(results.filter((record) => record.Description.includes("DIMM")));
console.log('#############################################################');
console.log('Ram')
console.log(results.filter((record) => record.Description.includes("MEM")));
console.log("Merci de m'avoir utilisé !");
2022-02-27 04:18:11 +01:00
});
})();