Class: MMonitor::Strategies::Suning
- Inherits:
-
Parser
- Object
- Parser
- MMonitor::Strategies::Suning
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
Instance Method Details
#css_path ⇒ Object
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_key ⇒ Object
44
45
46
|
# File 'lib/mmonitor/strategies/suning.rb', line 44
def page_key
'cp'
end
|
#price ⇒ Object
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_url ⇒ Object
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
|
#provider ⇒ Object
8
9
10
|
# File 'lib/mmonitor/strategies/suning.rb', line 8
def provider
:suning
end
|
#sku_id ⇒ Object
31
32
33
|
# File 'lib/mmonitor/strategies/suning.rb', line 31
def sku_id
self.item[css_path[:sku_id]].split(' ')[0]
end
|
#spu_id ⇒ Object
27
28
29
|
# File 'lib/mmonitor/strategies/suning.rb', line 27
def spu_id
self.item[css_path[:spu_id]].to_i
end
|