Skip to content

Instantly share code, notes, and snippets.

@thomasnordquist
Created March 3, 2016 13:34
Show Gist options
  • Save thomasnordquist/b6b566a7d5d1a84fe86d to your computer and use it in GitHub Desktop.
Save thomasnordquist/b6b566a7d5d1a84fe86d to your computer and use it in GitHub Desktop.
Scrapes current trains and busses from your bus/train station
/*
Dependencies: request, cheerio
npm install cheerio
npm install request
Run with:
node db.js
*/
var cheerio = require('cheerio');
var request = require('request');
/**
* @var dbUrl visit https://reiseauskunft.bahn.de/bin/bhftafel.exe and copy the link of the refresh button
*/
var dbUrl = 'https://reiseauskunft.bahn.de/bin/bhftafel.exe/dn?ld=15064&rt=1&input=Darmstadt%20Hbf%238000068&boardType=dep&time=actual&productsFilter=000001001&start=yes';
request(dbUrl, function(error, result, body) {
$ = cheerio.load(body);
var routes = $('table.result tr');
routes = routes.filter(function (key, line) {
return /journeyRow_[0-9]+/.test( $(line).attr('id') );
});
routes.each(function(key, route) {
var time = $(route).find('td.time').first().text().trim();
var train = $(route).find('td.train a').text().replace(/\s+/g,' ').trim();
var dest = $(route).find('td.route a').text().trim();
console.log(time + " - " + train + " - " + dest)
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment