-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
74 lines (53 loc) · 2.13 KB
/
test.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
const puppeteer = require('puppeteer');
const rootPage = "http://es.surf-forecast.com/breaks/Playade-Gros/forecasts/latest";
// (TODO) Make an array of webpages of different spots
let scrape = async () => {
//OPEN PAGE
const browser = await puppeteer.launch({args: ['--no-sandbox'], timeout:0});
const page = await browser.newPage();
await page.goto(rootPage);
//SELECT ITEMS
const result = await page.evaluate(() => {
let elements = document.querySelectorAll('#target-for-range-tabs > tbody > tr.lar.hea.table-start.class_name');
let horas = document.querySelectorAll('#target-for-range-tabs > tbody > tr.hea1.table-end.lar.class_name > td');
let swells = document.querySelectorAll('.swell-icon-val');
let swellDirections = document.querySelectorAll('#target-for-range-tabs > tbody > tr:nth-child(4) > td')
let horasArr = [];
let swellArr = [];
let swellDirArr = [];
let daysArr = [];
//DAYS
for (var element of elements){
let firstDay = element.childNodes[1].innerText;
let secondDay = element.childNodes[2].innerText;
let thirdDay = element.childNodes[3].innerText;
data.push({firstDay,secondDay,thirdDay});
}
//HOURS
for (var hora of horas){
let time = hora.innerText;
horasArr.push({time});
}
//SWELL
for( var swell of swells){
let measure = swell.childNodes[0].nodeValue;
swellArr.push({measure});
}
//SWELL DIRECTION
for( var swellDirection of swellDirections){
let direction = swellDirection.childNodes[2].nodeValue;
swellDirArr.push({direction});
}
//COMPLETE CHART (HOUR, SWELL, DIRECTION)
var chart = horasArr.map((hora,i)=>{
return newChart = {...hora, ...swellArr[i],...swellDirArr[i]}
})
return chart;
});
browser.close();
return result;
};
//SCRAPE FORECAST
scrape().then((value) => {
console.log(value);
});