class ESpider::Front::Dianping::Hotel::Detail
Public Class Methods
new(id)
click to toggle source
# File lib/espider/front/dianping/hotel/detail.rb, line 6 def initialize(id) @host = 'www.dianping.com' @id = id @current_url = URI::HTTP.build( :host => @host, :path => "/shop/#{id}" ).to_s @options = { :headers => { "User-Agent" => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36' } } @hotel = Nokogiri::HTML(HTTParty.get(@current_url,@options)) @js = @hotel.search("//script[@class='J_auto-load']").map{|script|script.inner_html}.join("\n") @js = Nokogiri::HTML(@js) end
Public Instance Methods
comments()
click to toggle source
# File lib/espider/front/dianping/hotel/detail.rb, line 73 def comments @hotel.search("//div[@class='J_brief-cont']").map{|comment|comment.text.strip} end
facilities()
click to toggle source
return example:
- {“title”=>“客房设施”, “tags”=>[“国内长途电话”, “国际长途电话”, “拖鞋”, “雨伞”, “书桌”, “24小时热水”, “电热水壶”, “咖啡壶/茶壶”, “免费洗漱用品(6样以上)”, “免费瓶装水”, “迷你吧”, “小冰箱”, “浴衣”, “多种规格电源插座”, “110V电压插座”, “浴缸”, “独立淋浴间”, “吹风机”, “房内保险箱”, “中央空调”]}, {“title”=>“服务项目”, “tags”=>[“棋牌室”, “室内游泳池”, “健身室”, “按摩室”, “桑拿浴室”, “足浴”, “SPA”, “烧烤”]}, {“title”=>“活动设施”, “tags”=>[“中餐厅”, “西餐厅”, “酒吧”, “前台贵重物品保险柜”, “免费停车场”, “有可无线上网的公共区域”, “大堂吧”, “电梯”, “有可无线上网的公共区域 免费”]}, {“title”=>“综合设施”, “tags”=>[“会议厅”, “商务中心”, “外币兑换服务”, “旅游票务服务”, “洗衣服务”, “送餐服务”, “专职行李员”, “行李寄存”, “叫醒服务”, “接机服务”]}
# File lib/espider/front/dianping/hotel/detail.rb, line 33 def facilities return @facilities if @facilities @facilities = [] @js.search("//div[@class='introd-box']//li").each do |li| facility = {} title = li.search("span[@class='tit']").first next unless title facility['title'] = title.text facility['tags'] = [] li.search("span[@class='introd-tag']").each do |tag| facility['tags'] << tag.text end @facilities << facility end @facilities end
images()
click to toggle source
return example:
- {:url=>“www.dianping.com/photos/38858830”, :text=>“门面”, :small_pic=>“
”, :big_pic=>“
”}, {:url=>“www.dianping.com/photos/38858827”, :text=>“门面”, :small_pic=>“
”, :big_pic=>“
”}, {:url=>“www.dianping.com/photos/38858820”, :text=>“门面”, :small_pic=>“
”, :big_pic=>“
”}, {:url=>“www.dianping.com/photos/38858806”, :text=>“门面”, :small_pic=>“
”, :big_pic=>“
”}, {:url=>“www.dianping.com/photos/38858804”, :text=>“门面”, :small_pic=>“
”, :big_pic=>“
”}, {:url=>“www.dianping.com/photos/38858801”, :text=>“门面”, :small_pic=>“
”, :big_pic=>“
”}, {:url=>“www.dianping.com/photos/38858799”, :text=>“门面”, :small_pic=>“
”, :big_pic=>“
”}, {:url=>“www.dianping.com/photos/38858782”, :text=>“门面”, :small_pic=>“
”, :big_pic=>“
”}, {:url=>“www.dianping.com/photos/38858781”, :text=>“门面”, :small_pic=>“
”, :big_pic=>“
”}, {:url=>“www.dianping.com/photos/38858777”, :text=>“门面”, :small_pic=>“
”, :big_pic=>“
”}, {:url=>“www.dianping.com/photos/38858769”, :text=>“门面”, :small_pic=>“
”, :big_pic=>“
”}, {:url=>“www.dianping.com/photos/38858762”, :text=>“大堂”, :small_pic=>“
”, :big_pic=>“
”}, {:url=>“www.dianping.com/photos/38858758”, :text=>“门面”, :small_pic=>“
”, :big_pic=>“
”}, {:url=>“www.dianping.com/photos/38858752”, :text=>“大堂”, :small_pic=>“
”, :big_pic=>“
”}, {:url=>“www.dianping.com/photos/38858748”, :text=>“大堂”, :small_pic=>“
”, :big_pic=>“
”}
# File lib/espider/front/dianping/hotel/detail.rb, line 52 def images url = URI::HTTP.build( :host => @host, :path => "/shop/#@id/photos" ) images = Nokogiri::HTML(HTTParty.get(url.to_s,@options)) results = [] images.search("//li[@class='J_list']").each do |image| href = image.search("div/a").first['href'] text = image.search("h3/a").text thumb = image.search("img").first['src'] results << { :url => URI.join(@current_url,href).to_s, :text => text, :small_pic => thumb, :big_pic => thumb.sub(/\(.+\)/,'(700x700)') } end results end
intro()
click to toggle source
# File lib/espider/front/dianping/hotel/detail.rb, line 27 def intro @js.search("//div[@class='intro-txt J_hotel-expand']/span[@class='Hide']").text end
name()
click to toggle source
# File lib/espider/front/dianping/hotel/detail.rb, line 23 def name @hotel.search("//h1").first.text end