Class: MMonitor::Strategies::Suning

Inherits:
Parser
  • Object
show all
Defined in:
lib/mmonitor/strategies/suning.rb

Overview

Instance Attribute Summary

Attributes inherited from Parser

#body, #item, #items

Instance Method Summary collapse

Methods inherited from Parser

#extra, #initialize, #list, #pages, #photo_url, #process, #tag_price, #title, #total

Constructor Details

This class inherits a constructor from MMonitor::Parser

Instance Method Details

#css_pathObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mmonitor/strategies/suning.rb', line 12

def css_path
  {
    body:      'body>div.wrap-search>div.w1190>div.proList.mb10',
    list:      'div#productTab>div#proShow>ul.container',
    item:      'li.item',
    total:     'div#filterContent>div.searchKeyT>i',
    pages:     '#refresh>div.page>span>i#pageTotal',
    spu_id:    'name',
    sku_id:    'class',
    title:     'div > span > a > p',
    photo_url: 'a > img',
    price_url: 'div > p > img'
  }
end

#get_html(url, params) ⇒ Object



52
53
54
55
56
# File 'lib/mmonitor/strategies/suning.rb', line 52

def get_html(url, params)
  uri = Addressable::URI.new
  uri.query_values = params
  Spider.get_html("#{url}&#{uri.query}")
end

#page(num) ⇒ Object



48
49
50
# File 'lib/mmonitor/strategies/suning.rb', line 48

def page(num)
  num-1
end

#page_keyObject



44
45
46
# File 'lib/mmonitor/strategies/suning.rb', line 44

def page_key
  'cp'
end

#priceObject



40
41
42
# File 'lib/mmonitor/strategies/suning.rb', line 40

def price
  price_from_ajax(sku_id) || pirce_from_ocr(price_url)
end

#price_urlObject

产品售价图片(可选)



35
36
37
38
# File 'lib/mmonitor/strategies/suning.rb', line 35

def price_url # 产品售价图片(可选)
  dom = self.item.at(css_path[:price_url])
  dom['src2'] unless dom.nil?
end

#providerObject

输出的产品



8
9
10
# File 'lib/mmonitor/strategies/suning.rb', line 8

def provider
  :suning
end

#sku_idObject



31
32
33
# File 'lib/mmonitor/strategies/suning.rb', line 31

def sku_id
  self.item[css_path[:sku_id]].split(' ')[0]
end

#spu_idObject



27
28
29
# File 'lib/mmonitor/strategies/suning.rb', line 27

def spu_id
  self.item[css_path[:spu_id]].to_i
end