-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
75 lines (53 loc) · 1.94 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const p = require('puppeteer');
const each = require('promise-each');
const notifier = require('node-notifier');
const { mainPage, detailedSearchPage, resultsPage, propertyPage } = require('./page-elements') ;
const { searchedAreas } = require('./search-parameters');
const setSearchDetails = require('./phases/search-details');
const scrapeLinks = require('./phases/scraping-links');
const iterateOnLinks = require('./phases/result-iteration');
(async () => {
let browser;
let page;
try {
browser = await p.launch();
page = await browser.newPage();
console.log('Hello! 👋 I\'m starting right away.');
notifier.notify({
'title': '🏡 ingatlan.com 🤖',
'message': 'Hello! 👋 I\'m starting right away.'
});
await page.goto('https://ingatlan.com')
.then(console.log('✅ Found ingatlan.com'));
console.log('➡️ Moving onto the search details.');
await Promise.resolve(searchedAreas).then(each(async (area, currentAreaIndex) => {
console.log(` 🔎 Setting search data for ${area}.`);
await setSearchDetails(page, mainPage, detailedSearchPage, area);
/*
Arriving to results page
*/
const links = await scrapeLinks(page, resultsPage);
console.log(`➡️ Moving onto iteration phase of ${area}.`);
/*
Iteration on results
*/
await iterateOnLinks(page, propertyPage, links, area);
if (currentAreaIndex !== searchedAreas.length - 1) {
await page.goto('https://ingatlan.com')
.then(console.log('⬅️ Going back to ingatlan.com'));
}
}));
console.log(`🎉 I'm done. Bye. 👋`);
notifier.notify({
'title': '🏡 ingatlan.com 🤖',
'message': '🎉 I\'m done. Bye. 👋`'
});
} catch (e) {
console.error(`❌ ${e}`);
notifier.notify({
'title': '🏡 ingatlan.com 🤖',
'message': '❌ Something happened. Sorry!'
});
}
browser.close();
})();