Class: Qunar::HotelList
- Inherits:
-
Object
- Object
- Qunar::HotelList
- Includes:
- Capybara::DSL
- Defined in:
- lib/qunar/hotel_list.rb
Instance Method Summary collapse
-
#hotels_in_ajax(page_id) ⇒ Object
Call ajax for more hotels of each page.
-
#html ⇒ Object
Html file.
-
#initialize(city_url) ⇒ HotelList
constructor
A new instance of HotelList.
Constructor Details
#initialize(city_url) ⇒ HotelList
Returns a new instance of HotelList.
4 5 6 7 8 9 10 |
# File 'lib/qunar/hotel_list.rb', line 4 def initialize(city_url) @city = city_url Capybara.current_driver = :webkit Capybara.default_selector = :xpath Capybara.app_host ='http://touch.qunar.com' page.driver.header 'User-Agent' ,"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.91 Safari/537.36" end |
Instance Method Details
#hotels_in_ajax(page_id) ⇒ Object
Call ajax for more hotels of each page
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/qunar/hotel_list.rb', line 13 def hotels_in_ajax(page_id) sleep(2) # sleep for 2 seconds @uri = "/h5/hotel/hotellist?cityUrl=#{@city}&page=#{page_id}&tpl=hotel.hotelListTpl" page.visit @uri @html = Nokogiri::HTML page.html qn_list = @html.xpath("//li[@class='qn_bt']") # Collect hotels hotels = qn_list.collect { |hotel| title = hotel.at("./div/div[@class='title']") item = { :city=>@city, :qunar_id=>hotel['data-seq'], :hotel_name=>title.nil? ? nil : title.text.strip } } hotels.empty? ? nil : hotels end |
#html ⇒ Object
Html file
27 28 29 |
# File 'lib/qunar/hotel_list.rb', line 27 def html @html end |