-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (47 loc) · 1.6 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const puppeteer = require("puppeteer-extra");
const cheerio = require("cheerio");
const StealthPlugin = require("puppeteer-extra-plugin-stealth");
const { analyzeDataV2, getHTMLContent, getDatas } = require("./utils");
puppeteer.use(StealthPlugin());
const KM = 170000;
const url =
"https://www.sahibinden.com/hyundai-i30-1.4-cvvt-team?pagingSize=50";
const data = [];
let $;
(async () => {
//#region data fetching
const browser = await puppeteer.launch({
headless: true,
});
const page = await browser.newPage();
await page.goto(url, {
waitUntil: "domcontentloaded",
});
do {
const htmlContent = await getHTMLContent(page);
$ = cheerio.load(htmlContent);
const rows = $("tbody tr");
const datas = await getDatas($, rows);
data.push(...datas);
await page.$eval("a.prevNextBut", (a) => a.click());
} while (
$(".prevNextBut").length > 0 &&
$(".prevNextBut").attr("title") === "Sonraki"
);
await browser.close();
//#endregion
console.log("V2 Analysis");
let analysisV2 = analyzeDataV2(data, KM);
console.log(`Mean Price: ${analysisV2.mean}`);
console.log(`Median Price: ${analysisV2.median}`);
console.log(`Q1 Price: ${analysisV2.q1}`);
console.log(`Q3 Price: ${analysisV2.q3}`);
console.log(`IQR: ${analysisV2.iqr}`);
console.log(`Predicted Price for ${KM} km: ${analysisV2.predictedPrice}`);
console.log(
`Correlation between Price and Mileage: ${analysisV2.correlation}`
);
// strategy: median between median and Q1
let finalPrice = (analysisV2.median + analysisV2.q1) / 2;
console.log(`Recommended Sale Price: ${finalPrice}`);
})();