Skip to content

Instantly share code, notes, and snippets.

@siuying
Created May 31, 2009 17:47
Show Gist options
  • Save siuying/120955 to your computer and use it in GitHub Desktop.
Save siuying/120955 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'scrubyt'
require 'nokogiri'
require 'iconv'
# Fetch the seatplan for the schedule
movies = Scrubyt::Extractor.define do
# use a proper schedule link here
fetch "http://www2.cinema.com.hk/revamp/html/show_seat.php?lang=c&show_id=13105241"
# schedule info
schedule "//table[2]" do
cinema "//tr[1]/td[2]"
house "//tr[2]/td[2]"
movie "//tr[3]/td[2]"
cat "//tr[4]/td[2]"
time "//tr[5]/td[2]"
end
# seats info
seatplan "//body" do
row "//table//table//table//table//table//table//table//tr" do
label("//td[@class='seat_C']").select_indices(:first)
seat "//td[@class='seat_A']"
end
end
end
# count how many seats available, insert it into result, and remove seatplan details
result = Nokogiri::XML(movies.to_xml, nil, "BIG-5")
(result/"//seatplan").each do |seatplan|
seats = Nokogiri::XML::Element.new("seats", seatplan.document)
seats.content = (seatplan/"//seat").size
(result/"//schedule").each do |schedule|
schedule.add_child(seats)
end
seatplan.unlink
end
puts result.to_s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment