-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrape.js
executable file
·45 lines (41 loc) · 2.63 KB
/
scrape.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
#!/usr/bin/env node
"use strict"
const request = require('request');
const cheerio = require('cheerio');
request('https://www.tnagrisnet.tn.gov.in/ARS/home/reservoir', (response, error, html) => {
const $ = cheerio.load(html)
const heading = $('.text-center')
const date = heading.children().text()
let x = date.split('-')
let result = {
Title: heading.html(),
Date: (x[1] + "/" + x[2] + "/" + x[3]).trim(),
Dams: [
{
Reservoir: $('body > div.container > div > div > table > tbody > tr:nth-child(3) > td:nth-child(1)').text().trim(),
FullDepth: $('body > div.container > div > div > table > tbody > tr:nth-child(3) > td:nth-child(2)').text(),
CurrentWaterLevel: $('body > div.container > div > div > table > tbody > tr:nth-child(3) > td:nth-child(4)').text(),
LastYearLevel: $('body > div.container > div > div > table > tbody > tr:nth-child(3) > td:nth-child(8)').text()
},
{
Reservoir: $('body > div.container > div > div > table > tbody > tr:nth-child(9) > td:nth-child(1)').text().trim(),
FullDepth: $('body > div.container > div > div > table > tbody > tr:nth-child(9) > td:nth-child(2)').text(),
CurrentWaterLevel: $('body > div.container > div > div > table > tbody > tr:nth-child(9) > td:nth-child(4)').text(),
LastYearLevel: $('body > div.container > div > div > table > tbody > tr:nth-child(9) > td:nth-child(8)').text()
},
{
Reservoir: $('body > div.container > div > div > table > tbody > tr:nth-child(5) > td:nth-child(1)').text().trim(),
FullDepth: $('body > div.container > div > div > table > tbody > tr:nth-child(5) > td:nth-child(2)').text(),
CurrentWaterLevel: $('body > div.container > div > div > table > tbody > tr:nth-child(5) > td:nth-child(4)').text(),
LastYearLevel: $('body > div.container > div > div > table > tbody > tr:nth-child(5) > td:nth-child(8)').text()
},
{
Reservoir: $('body > div.container > div > div > table > tbody > tr:nth-child(7) > td:nth-child(1)').text().trim(),
FullDepth: $('body > div.container > div > div > table > tbody > tr:nth-child(7) > td:nth-child(2)').text(),
CurrentWaterLevel: $('body > div.container > div > div > table > tbody > tr:nth-child(7) > td:nth-child(4)').text(),
LastYearLevel: $('body > div.container > div > div > table > tbody > tr:nth-child(7) > td:nth-child(8)').text()
}
]
}
console.log(result)
});