-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (44 loc) · 1.43 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
const puppeteer = require('puppeteer');
const config = require('./config.json');
(async () => {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto(`https://www.rightmove.co.uk/property-for-sale/search.html?searchLocation=${config.searchPostcode}&locationIdentifier=&useLocationIdentifier=false&buy=For+sale`);
const fields = {
select: [
'radius',
'displayPropertyType',
'minPrice',
'maxPrice',
'minBedrooms',
'maxBedrooms',
'maxDaysSinceAdded'
]
}
const getSelectableElementValues = (field) => {
return page.evaluate((field) => {
return Array.from(document.getElementById(field), e => ({
option: e.innerText,
optionValue: e.value,
}))
}, field);
}
const setRadius = () => {
page.select('#radius', '40.0')
}
const submitForm = async () => {
console.log("Submitting form...");
await page.click('#submit');
}
await Promise.all(fields.select.map(field => getSelectableElementValues(field))).then(
results => {
console.log(results);
}
).then(
async () => {
await setRadius();
await submitForm();
browser.close().then(() => console.log("Completed successfully."));
}
);
})();