Class: MMonitor::Strategies::Tmall

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

Overview

Instance Attribute Summary

Attributes inherited from Parser

#body, #item, #items

Instance Method Summary collapse

Methods inherited from Parser

#extra, #get_html, #initialize, #list, #page, #price, #price_url, #process, #sku_id, #spu_id, #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
# File 'lib/mmonitor/strategies/tmall.rb', line 12

def css_path
  {
    body:      '#TmshopSrchNav>div',
    list:      'div.J_TItems',
    item:      'dl.item',
    pages:     'div.filter.clearfix.J_TFilter > p > b.ui-page-s-len', # .text.split('/')[1]
    spu_id:    'data-id',
    title:     'dd.detail > a',
    photo_url: 'dt > a:nth-child(1) > img', # 'data-ks-lazyload'
    price:     'dd.detail > div > div.cprice-area > span.c-price'
  }
end

#page_keyObject



33
34
35
# File 'lib/mmonitor/strategies/tmall.rb', line 33

def page_key
  'pageNo'
end

#pagesObject



29
30
31
# File 'lib/mmonitor/strategies/tmall.rb', line 29

def pages
  self.body.at(css_path[:pages]).text.split('/')[1].to_i
end

#photo_urlObject

产品图片



25
26
27
# File 'lib/mmonitor/strategies/tmall.rb', line 25

def photo_url # 产品图片
  self.item.at(css_path[:photo_url])['data-ks-lazyload']
end

#providerObject

输出的产品



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

def provider
  :tmall
end