Permalink
Browse files

Fixes #10: add timeanddate scraper

  • Loading branch information...
vibhcool committed Jun 1, 2017
1 parent fee4105 commit 0e616983b4bc98df76b5370e59e1d2db6363d975
Showing with 63 additions and 0 deletions.
  1. +63 −0 scrapers/timeanddate.js
@@ -0,0 +1,63 @@
/* Usage : timeanddate.js London
timeanddate.js
*/
const request = require('request-promise-native');
const cheerio = require('cheerio');
var url;
var html;
var $;
if (process.argv.length === 3) {
query = process.argv[2];
terms = ['all'];
}
url = "http://www.timeanddate.com/worldclock/results.html?query=" + query;
request(url, function(error, response, body) {
if(error) {
console.log("Error: " + error);
process.exit(-1);
}
html = body;
scrapeTimeAndDate()
});
function scrapeTimeAndDate() {
$ = cheerio.load(html);
var loc_list = {};
var htmlTime = $("table");
var tag, location, time;
var locationwisetime = [];
var count = 0;
$('table').find('tr').each(function (index, element) {
tag = $(element).find("td");
if( tag.text() != "") {
location = tag.text();
tag = tag.next();
time = tag.text();
location = location.replace(time,"");
loc_list["location"] = location;
loc_list["time"] = time;
locationwisetime.push(loc_list);
count++;
loc_list = {};
} else {
tag = tag.next();
}
});
loc_list["count"] = count;
locationwisetime.push(loc_list);
console.log(locationwisetime);
}

0 comments on commit 0e61698

Please sign in to comment.