Class: Qunar::Rank
Instance Method Summary collapse
-
#initialize(hotelId) ⇒ Rank
constructor
A new instance of Rank.
-
#room ⇒ Object
File.open(“test1.html”,“w”) do |file| file.puts @page end.
Constructor Details
#initialize(hotelId) ⇒ Rank
Returns a new instance of Rank.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/qunar/rank.rb', line 18 def initialize(hotelId) raise "id should be string" if !hotelId.instance_of?(String) @HotelSEQ = hotelId #hotelId is "cityurl_hotelcode" @cityurl = hotelId[0..hotelId.rindex("_",-1)-1] @hotelcode = hotelId[hotelId.rindex("_",-1)+1..hotelId.length] @uri = URI(File.join('/city', @cityurl, "dt-#{@hotelcode}")) visit @uri all('//*[text()="展开报价"]').each do |btn| btn.click end #@page = Capybara.current_session.driver.browser.page_source #use when choose capybara driver selenium @page = .current_session.driver.browser.body #use when choose capybara driver webkit @hotel = Nokogiri::HTML @page File.open("test1.html","w") do |file| file.puts @page end end |
Instance Method Details
#room ⇒ Object
File.open(“test1.html”,“w”) do |file|
file.puts @page
end
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/qunar/rank.rb', line 41 def room room = {} @hotel.search("//ul[@class='htl-type-list clrfix']/li").each do |li| type = li.search("span[@class='type-name']").first.text.strip li.search("div[@class='similar-type-agent-list']/div/div").each do |row| ota_pic = row.search("div[@class='agent-pic']/img").first['src'].strip bookable = row.search("a[@class='btn-book']/span").first.text.strip insurance = row.search("p[@class='dbt-ct']").first if insurance == nil insurance = false else insurance = true end coupon = row.search("span[@class='fan']/em[@class='pr'] |span[@class='fan laps']/em[@class='pr']").first if coupon == nil coupon = '0' else coupon = coupon.text.sub(/¥/,'').strip end prepay = row.search("span[@title='需要预先支付房款']").first if prepay == nil prepay = false else prepay = true end price = row.search("p[@class='final-price ']/b").first.text.strip neat_price = row.search("p[@class='count_pr']").first.text puts "#{type} #{ota_pic} #{price} #{neat_price} #{coupon} #{prepay} #{insurance} #{bookable}" end end return 0 end |