Last active
August 29, 2015 13:58
-
-
Save luckyruby/10367250 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var args = require('system').args; | |
var page = require('webpage').create(); | |
var loc = encodeURIComponent(args[1]); | |
var pickup_date = encodeURIComponent(args[2]); | |
var pickup_time = encodeURIComponent(args[3]); | |
var return_date = encodeURIComponent(args[4]); | |
var return_time = encodeURIComponent(args[5]); | |
var url = "http://www.orbitz.com/shop/home?type=car&car.pickupType=AIRPORT&car.dropoffType=SAME&car.airport.orig.key=" + args[1] + "&car.airport.startDate=" + pickup_date + "&car.airport.pickupTime=" + pickup_time + "&car.airport.endDate=" + return_date + "&car.airport.dropoffTime=" + return_time + "&car.airport.airConditioning=U&car.airport.transmissionType=U&search=Search+Cars" | |
page.open(url, function() { | |
var results = page.evaluate(function() { | |
return document.querySelector("table").outerHTML; | |
}); | |
console.log(results); | |
phantom.exit(); | |
}); |
This file contains hidden or 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
require 'nokogiri' | |
require 'pp' | |
class Shop | |
attr_accessor :location, :pickup_date, :pickup_time, :return_date, :return_time | |
attr_reader :run_time, :results | |
def initialize(attributes={}) | |
attributes.each {|k,v| self.send("#{k}=",v)} | |
end | |
def new | |
end | |
def run | |
@run_time = Time.now | |
@doc = Nokogiri::HTML(html) | |
@companies = @doc.css('.columnHeaderSeparator .headerLink').map {|i| i.text}.uniq | |
@cartypes = @doc.css('.rowHeader .headerLink').map {|i| i.text}.uniq | |
@rates = @doc.css('.unitPrice').map {|i| i.text[/\$(\d+)/,1]} | |
@ratetypes = @doc.css('.unitPrice').map {|i| i.text[/\/(\w+)/,1]} | |
@totals = @doc.css('.totalPrice').map {|i| i.text[/\$(\d+)/,1]} | |
construct_results | |
end | |
private | |
def html | |
`phantomjs orbitz.js #{location} #{pickup_date} #{pickup_time} #{return_date} #{return_time}` | |
end | |
def construct_results | |
@results = {} | |
@companies.each {|c| results[c] = {}} | |
idx = 0 | |
@cartypes.each do |car| | |
@companies.each do |company| | |
@results[company][car] = { | |
rate: @rates[idx], | |
ratetype: @ratetypes[idx], | |
totalprice: @totals[idx] | |
} | |
idx += 1 | |
end | |
end | |
end | |
end | |
shop_params = { | |
location: 'bos', | |
pickup_date: '4/15/14', | |
pickup_time: '11AM', | |
return_date: '4/20/14', | |
return_time: '11AM' | |
} | |
shop = Shop.new(shop_params) | |
shop.run | |
pp shop.results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment