class ESpider::Front::Baidu::Map::Hotel::List
Constants
- ListUri
Attributes
total[R]
Public Class Methods
new(city_cn)
click to toggle source
# File lib/espider/front/baidu/map/hotel/list.rb, line 12 def initialize(city_cn) @wd = URI.encode city_cn + '+' + '酒店' @pn=1 url = ListUri+"?newmap=1&reqflag=pcmap&biz=1&qt=s&wd=#{@wd}&c=1&src=0&wd2=&sug=0&l=4&from=webmap&tn=B_NORMAL_MAP&nn=0&ie=utf-8" @hotels = HTTParty.get url @total = count_page_num end
Public Instance Methods
list()
click to toggle source
# File lib/espider/front/baidu/map/hotel/list.rb, line 27 def list parsed_json = JSON.parse @hotels results = [] return nil if parsed_json['content'].nil? parsed_json['content'].each do |hotel| results << hotel end results end
next_page()
click to toggle source
# File lib/espider/front/baidu/map/hotel/list.rb, line 19 def next_page return false if (@pn+1)*10 > @total @pn += 1 url = "http://map.baidu.com/?newmap=1&reqflag=pcmap&biz=1&qt=s&wd=#{@wd}&c=1&src=0&sug=0&l=4&from=webmap&rn=10&pl_data_type=hotel&pn=#{@pn}" p url @hotels = HTTParty.get url true end
Private Instance Methods
count_page_num()
click to toggle source
# File lib/espider/front/baidu/map/hotel/list.rb, line 37 def count_page_num parsed_json = JSON.parse @hotels parsed_json['result']['total'] end