Class: ESpider::Front::Kuxun::Detail
- Inherits:
-
Object
- Object
- ESpider::Front::Kuxun::Detail
- Defined in:
- lib/espider/front/kuxun/detail.rb
Instance Method Summary collapse
- #address ⇒ Object
-
#facilities ⇒ Object
example: [“tags”=>[“商务中心”, “送餐服务”, “洗衣服务”, “叫醒服务”, “旅游服务”, “前台贵重物品保险柜”, “收费停车”, “外币兑换”, “公共区域免费Wi-Fi”], “tags“=>, ”tags“=>[”多功能厅:剧院式可容纳80人“, ”另有2个会议室,均容纳30人“], ”tags“=>[”中餐厅:主营鲁菜、川菜、可提供北京风味小吃“, ”西餐厅:可提供中西自助餐、酒水“]].
-
#images ⇒ Object
example: [:small_pic=>“
”, :big_pic=>“
”, :small_pic=>“
”, :big_pic=>“
”, :small_pic=>“
”, :big_pic=>“
”. -
#initialize(id) ⇒ Detail
constructor
id example: beijing-xihuajingzhao.
- #intro ⇒ Object
- #name ⇒ Object
- #xy ⇒ Object
Constructor Details
#initialize(id) ⇒ Detail
id example: beijing-xihuajingzhao
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/espider/front/kuxun/detail.rb', line 10 def initialize(id) @id = id @host = 'jiudian.kuxun.cn' @current_url = URI::HTTP.build( :host => @host, :path => "/#{@id}-jiudian.html" ).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)) end |
Instance Method Details
#address ⇒ Object
30 31 32 33 |
# File 'lib/espider/front/kuxun/detail.rb', line 30 def address return '' if title_bd.nil? title_bd.search('p').first.text.gsub!(/\s+/, ' ').sub('地址:','').squeeze.strip end |
#facilities ⇒ Object
example:
- “tags”=>[“商务中心”, “送餐服务”, “洗衣服务”, “叫醒服务”, “旅游服务”, “前台贵重物品保险柜”, “收费停车”, “外币兑换”, “公共区域免费Wi-Fi”], “tags“=>, ”tags“=>[”多功能厅:剧院式可容纳80人“, ”另有2个会议室,均容纳30人“], ”tags“=>[”中餐厅:主营鲁菜、川菜、可提供北京风味小吃“, ”西餐厅:可提供中西自助餐、酒水“]
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/espider/front/kuxun/detail.rb', line 68 def facilities return @facilities if @facilities @facilities = [] @hotel.search("//ul[@class='OpenFacCont']/li").each do |li| title = li.search('b').first.text.strip = li.search('p').first.text.strip.sub(/。$/,'') if .include?';' = .split(';') else = .split('、') end @facilities << { 'title' => title, 'tags' => } end @facilities end |
#images ⇒ Object
example: [:small_pic=>“
”, :big_pic=>“
”, :small_pic=>“
”, :big_pic=>“
”, :small_pic=>“
”, :big_pic=>“
”
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/espider/front/kuxun/detail.rb', line 42 def images url = URI::HTTP.build( :host => @host, :path => "/#{@id}-jiudian-tupian.html" ).to_s = { :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' } } @images = Nokogiri::HTML(HTTParty.get(url,@options)) results = [] @images.search("//ul[@id='detail_image_全部']/li").each do |li| img = li.search('img').first['src'] img = li.search('img').first['original'] if img.include?'grey.gif' title = li.search('p').first results << { :text => title.text, :small_pic => img, :big_pic => img.sub(/H.jpg$/,'I.jpg') } end results end |
#intro ⇒ Object
35 36 37 38 |
# File 'lib/espider/front/kuxun/detail.rb', line 35 def intro return '' if title_bd.nil? or title_bd.search('p')[1].nil? title_bd.search('p')[1].text.squeeze.gsub('描述:','').strip end |
#name ⇒ Object
25 26 27 28 |
# File 'lib/espider/front/kuxun/detail.rb', line 25 def name return '' if @hotel.search("h1").first.nil? @hotel.search("h1").first.text.strip end |
#xy ⇒ Object
86 87 88 89 90 |
# File 'lib/espider/front/kuxun/detail.rb', line 86 def xy src = @hotel.to_s return [0, 0] if src.match(/var\s+b_longitude\s+=\s+\"(\d+\.\d+)\"/).nil? return [src.match(/var\s+b_longitude\s+=\s+\"(\d+\.\d+)\"/)[1], src.match(/var\s+b_latitude\s+=\s+\"(\d+\.\d+)\"/)[1]] end |