Skip to content

Instantly share code, notes, and snippets.

@ptica
Created April 14, 2011 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ptica/920071 to your computer and use it in GitHub Desktop.
Save ptica/920071 to your computer and use it in GitHub Desktop.
get the connection you want from idos.cz
var repl = require('repl');
var cli = repl.start();
var tt = {
from: "Praha",
to: "Brno"
date: "14.3.2010",
time: "6:00",
}
var zombie = require("zombie");
var sqlite3 = require('sqlite3');
var db = new sqlite3.Database("db.sqlite");
var stmt = db.prepare("insert into trains (idos) values (?)");
// ask for the mobile version
var browser = new zombie.Browser({userAgent : "Mozilla/5.0(iPad; U; iPhone OS 3_2; en-us) AppleWebKit/531.21.10 Mobile/7B314"});
cli.context.browser = browser;
cli.context.zombie = zombie;
cli.context.next = function () {
browser.clickLink("· Následující spojení", function (e,browser,s){
cli.context.data = browser.querySelector('p:nth-child(4)');
cli.context.save();
});
};
cli.context.init = function () {
browser.visit("http://idos.cz/", function(e, browser, s) {
browser.fill("odkud", tt.from).fill("kam", tt.to);
browser.fill("datum", tt.date);
browser.fill("cas", tt.time);
browser.pressButton("input[type='submit']", function(err, browser, status) {
cli.context.data = browser.querySelector('p:nth-child(4)');
cli.context.save();
});
});
console.log('LOADING...');
}
cli.context.save = function () {
stmt.run(cli.context.data.outerHTML);
}
cli.context.init();
@zzen
Copy link

zzen commented Apr 14, 2011

nice… forked, added install instructions, DB table creation (if it's missing), fixed a couple comma/semicolon mistakes… missing pull request feature for gists :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment