Class: ESpider::Front::Baidu::Map::Hotel::List
- Inherits:
-
Object
- Object
- ESpider::Front::Baidu::Map::Hotel::List
- Defined in:
- lib/espider/front/baidu/map/hotel/list.rb
Constant Summary collapse
- ListUri =
"http://map.baidu.com/"
Instance Attribute Summary collapse
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#initialize(city_cn) ⇒ List
constructor
A new instance of List.
- #list ⇒ Object
- #next_page ⇒ Object
Constructor Details
#initialize(city_cn) ⇒ List
12 13 14 15 16 17 18 |
# 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 |
Instance Attribute Details
#total ⇒ Object (readonly)
Returns the value of attribute total.
10 11 12 |
# File 'lib/espider/front/baidu/map/hotel/list.rb', line 10 def total @total end |
Instance Method Details
#list ⇒ Object
27 28 29 30 31 32 33 34 35 |
# 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 ⇒ Object
19 20 21 22 23 24 25 26 |
# 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 |