Skip to content

Instantly share code, notes, and snippets.

@alisterscott
Created March 23, 2012 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alisterscott/2175328 to your computer and use it in GitHub Desktop.
Save alisterscott/2175328 to your computer and use it in GitHub Desktop.
retrieve prices in divs
require 'watir-webdriver'
require 'nokogiri'
require 'bench'
Watir::always_locate = false
b = Watir::Browser.start "http://www.expedia.com/Flights-Search?trip=oneway&leg1=from:SEA,to:SFO,departure:11%2F11%2F2012TANYT&passengers=children:0,adults:1,seniors:0,infantinlap:Y&options=cabinclass:coach,nopenalty:N,sortby:price&mode=search"
prices = []
benchmark 'code' do
div_html = Nokogiri::HTML b.div(:id => 'flightModuleList').html
fm_divs = div_html.css('div').select { |d| d['id'] =~ /^type(\d)+TotalPrice(\d)+$/ }
prices = fm_divs.collect { |d| d.content }
end
run 1
p prices
# benchmark 'code' do
# my_div = b.div(:id => 'flightModuleList')
# my_divs = my_div.divs.collect{ |d| d.id =~ /^flightModule(\d).+$/ }
# puts my_divs.count
# end
# run 1
b.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment