Class: ESpider::Front::Baidu::Map::Hotel::List

Inherits:
Object
  • Object
show all
Defined in:
lib/espider/front/baidu/map/hotel/list.rb

Constant Summary collapse

ListUri =
"http://map.baidu.com/"

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#totalObject (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

#listObject



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_pageObject



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