Class: ESpider::Front::Qunar::Hotel
- Defined in:
- lib/espider/front/qunar/hotel.rb
Constant Summary
Constants inherited from Base
Instance Method Summary collapse
-
#abstract_desc ⇒ Object
简略描述.
- #address ⇒ Object
- #brand ⇒ Object
- #citynameCn ⇒ Object
- #citynameEn ⇒ Object
- #comments ⇒ Object
- #decorate_date ⇒ Object
- #desc ⇒ Object
-
#facilities ⇒ Object
设施.
-
#good_comment ⇒ Object
好评.
- #id ⇒ Object
- #images ⇒ Object
-
#initialize(hotelId) ⇒ Hotel
constructor
A new instance of Hotel.
-
#insttime ⇒ Object
开业时间.
- #name ⇒ Object
- #phone ⇒ Object
- #reference_price ⇒ Object
- #score ⇒ Object
- #star ⇒ Object
-
#total_comment ⇒ Object
评论总数.
-
#traffic ⇒ Object
交通信息.
- #xy ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(hotelId) ⇒ Hotel
Returns a new instance of Hotel.
7 8 9 10 11 |
# File 'lib/espider/front/qunar/hotel.rb', line 7 def initialize(hotelId) super uri = URI(File.join(BaseUri, 'city', @cityurl, "dt-#{@hotelcode}")) @hotel = Nokogiri::HTML HTTParty.get(uri.to_s) end |
Instance Method Details
#abstract_desc ⇒ Object
简略描述
69 70 71 72 73 |
# File 'lib/espider/front/qunar/hotel.rb', line 69 def abstract_desc abstract_desc = @hotel.search("p[@class='h_desc']").first return "" if abstract_desc.nil? return abstract_desc.text.sub('描述:','').strip end |
#address ⇒ Object
49 50 51 52 53 |
# File 'lib/espider/front/qunar/hotel.rb', line 49 def address address = @hotel.search("div[@class='adress']/span").first return "" if address.nil? return address['title'].strip end |
#brand ⇒ Object
74 75 76 77 |
# File 'lib/espider/front/qunar/hotel.rb', line 74 def brand brand ||= @hotel.search("//li[contains(text(),'所属品牌:')]").text.sub('所属品牌:','').strip brand.strip end |
#citynameCn ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/espider/front/qunar/hotel.rb', line 39 def citynameCn match_data = @hotel.to_s.match(/var\s*cityName\s*=\s*\'\p{Han}+\'/u) return "" if match_data.nil? match_data = match_data[0].match(/\p{Han}+/u) return "" if match_data.nil? match_data[0].strip end |
#citynameEn ⇒ Object
36 37 38 |
# File 'lib/espider/front/qunar/hotel.rb', line 36 def citynameEn @cityurl.sub('_city','') end |
#comments ⇒ Object
132 133 134 135 136 137 |
# File 'lib/espider/front/qunar/hotel.rb', line 132 def comments url = "http://review.qunar.com/api/h/#{@qunar_id}/detail/rank/v1/page/1" comments = HTTParty.get url comments = JSON.parse comments comments['data']['list'].map{|comment| JSON.parse(comment['content'])['feedContent'] } end |
#decorate_date ⇒ Object
127 128 129 130 131 |
# File 'lib/espider/front/qunar/hotel.rb', line 127 def decorate_date match_data = @hotel.to_s.match(/最后装修时间:\d+年/) return "" if match_data.nil? match_data[0].strip end |
#desc ⇒ Object
58 59 60 61 62 |
# File 'lib/espider/front/qunar/hotel.rb', line 58 def desc desc = @hotel.search("p[@class='summery less_summery']").text desc = @hotel.search("p[@class='summery expan_summery']").text if desc.empty? desc.gsub(/[[:space:]]/, '') end |
#facilities ⇒ Object
设施
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/espider/front/qunar/hotel.rb', line 94 def facilities facility = @hotel.search("//div[@class=\"roundmilieu htintroborder\"]").first facilities = Array.new() unless facility.nil? facility.search("dl").each do |dl| ele = Hash.new facility_cata = dl.search("dt").first.text.delete(':') ele1 = Array.new dl.search("dd/ul/li").each do |facility_type| ele1 << facility_type.text end ele['name'] = facility_cata ele['info'] = ele1 facilities << ele end end facilities end |
#good_comment ⇒ Object
好评
147 148 149 150 151 152 153 |
# File 'lib/espider/front/qunar/hotel.rb', line 147 def good_comment url = "http://review.qunar.com/api/h/#{@qunar_id}/detail/rank/page/1?rate=positive" body = HTTParty.get url match_data = body.match(/"count":\d+/) return "0" if match_data.nil? match_data[0].sub(/\"count\":/,"") end |
#id ⇒ Object
46 47 48 |
# File 'lib/espider/front/qunar/hotel.rb', line 46 def id @qunar_id end |
#images ⇒ Object
154 155 156 157 158 159 |
# File 'lib/espider/front/qunar/hotel.rb', line 154 def images url = "http://hotel.qunar.com/render/hotelDetailAllImage.jsp?hotelseq=#{@qunar_id}" body = HTTParty.get url body = JSON.parse(body) return body['data']["all"] if(body['ret']) end |
#insttime ⇒ Object
开业时间
64 65 66 67 |
# File 'lib/espider/front/qunar/hotel.rb', line 64 def insttime date ||= @hotel.search("p[@class='insttime']/cite").text.sub("开业时间:","") date.strip end |
#name ⇒ Object
12 13 14 15 16 |
# File 'lib/espider/front/qunar/hotel.rb', line 12 def name name_tag = @hotel.search('//dl[@class="eriefinfo"]//dt').first return nil if name_tag.nil? name_tag.text[0..name_tag.text.index("\n",1)].strip end |
#phone ⇒ Object
54 55 56 57 |
# File 'lib/espider/front/qunar/hotel.rb', line 54 def phone phone ||= @hotel.search("//li[contains(text(),'电话:')]").text.sub('电话:','').strip phone end |
#reference_price ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/espider/front/qunar/hotel.rb', line 78 def reference_price match_data = @hotel.to_s.match(/var\s*miniRetailPrice\s*=\s*\'\d+\';/) return 0 if match_data.nil? match_data = match_data[0].match(/[\d]+/) return 0 if match_data.nil? match_data[0].strip end |
#score ⇒ Object
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/espider/front/qunar/hotel.rb', line 160 def score url = "http://review.qunar.com/api/h/#{@qunar_id}/detail" body = HTTParty.get url begin body = JSON.parse body return body["data"]["score"].strip rescue Exception => e return "0.0" end end |
#star ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/espider/front/qunar/hotel.rb', line 17 def star name_tag = @hotel.search('//dl[@class="eriefinfo"]//dt').first return 0 if name_tag.nil? if name_tag.text.include?'经济型' 1 elsif name_tag.text.include?'舒适型' 3 elsif name_tag.text.include?'高档型' 4 elsif name_tag.text.include?'豪华型' 5 elsif name_tag.text.include?'star20' 2 elsif name_tag.text.include?'star50' 5 else 0 end end |
#total_comment ⇒ Object
评论总数
139 140 141 142 143 144 145 |
# File 'lib/espider/front/qunar/hotel.rb', line 139 def total_comment url = "http://review.qunar.com/api/h/#{@qunar_id}/detail/rank/page/1?rate=all" body = HTTParty.get url match_data = body.match(/"count":\d+/) return "0" if match_data.nil? match_data[0].sub(/\"count\":/,"").strip end |
#traffic ⇒ Object
交通信息
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/espider/front/qunar/hotel.rb', line 113 def traffic traffic = "http://hotel.qunar.com/detail/detailMapData.jsp?seq=#{@qunar_id}&type=traffic,canguan,jingdian,ent" traffic = HTTParty.get traffic traffic_data = Array.new() if traffic['ret'] == true traffic['data']['ent'].each do |line| ele = Hash.new ele['name'] = line['name'] ele['distance'] = line['distance'] traffic_data << ele end end traffic_data end |
#xy ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/espider/front/qunar/hotel.rb', line 85 def xy xy = @hotel.to_s.match(/hotelPoint=\[(\d+\.\d+),(\d+\.\d+)\];/) if xy.nil? return [0.0,0.0] else return [xy[1],xy[2]] end end |