-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscrape.js
48 lines (39 loc) · 1.27 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
46
47
48
var express = require('express');
var fs = require('fs');
var request = require('request');
var cheerio = require('cheerio');
var app = express();
exports.testModule = function () {
return "Connected to scrape.js";
};
//app.get('/scrape/content', function(req, res){
exports.scrapeSite = function () {
url = 'http://secure.parking.ucf.edu/GarageCount/';
var arr = [];
var string;
var jsonString = "{\n";
request(url, function(error, response, html){
if(!error){
var $ = cheerio.load(html);
$('.dxgv').each(function(i, elem){
arr[i] = $(this).text().trim();
});
var filtered = arr.filter(function (el) {
return el != "";
});
}
// Formatting array to JSON
for (var i = 0; i < 14; i = i + 2)
{
// New line of JSON for every garage (removing spaces from names)
jsonString += JSON.stringify(filtered[i].split(' ').join('')) + ":" + JSON.stringify(filtered[i+1]);
if (i < 12)
{
jsonString += ",\n";
}
}
jsonString += "\n}"; // Additional formatting
//console.log("JSON STRING IS :\n" + jsonString);
fs.writeFile('content.json', jsonString, function(err) {});
});
}