-
-
Save zzen/920093 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// install: npm install zombie sqlite3 | |
require.paths.unshift('./node_modules'); | |
var repl = require('repl'); | |
var cli = repl.start(); | |
var tt = { | |
from: "Praha", | |
to: "Brno", | |
date: "14.4.2011", | |
time: "8:00" | |
}; | |
var zombie = require("zombie"); | |
var sqlite3 = require('sqlite3'); | |
var db = new sqlite3.Database("db.sqlite"); | |
// 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 () { | |
db.serialize(function() { | |
db.run("CREATE TABLE IF NOT EXISTS trains (idos text)"); | |
var stmt = db.prepare("insert into trains (idos) values (?)"); | |
stmt.run(cli.context.data.outerHTML); | |
}); | |
}; | |
cli.context.init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment