Class: MMonitor::Strategies::Yhd
- Defined in:
- lib/mmonitor/strategies/yhd.rb
Overview
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#item ⇒ Object
Returns the value of attribute item.
-
#items ⇒ Object
Returns the value of attribute items.
-
#page ⇒ Object
Returns the value of attribute page.
-
#pages_count ⇒ Object
Returns the value of attribute pages_count.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #css_path ⇒ Object
-
#initialize(dom, url) ⇒ Yhd
constructor
A new instance of Yhd.
-
#pages ⇒ Object
分页伪装.
-
#photo_url ⇒ Object
产品图片.
-
#provider ⇒ Object
输出的产品.
-
#spu_id ⇒ Object
产品图片.
Methods inherited from Parser
#extra, #get_html, #list, #page_key, #price, #price_url, #process, #sku_id, #tag_price, #title, #total
Constructor Details
#initialize(dom, url) ⇒ Yhd
Returns a new instance of Yhd.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/mmonitor/strategies/yhd.rb', line 10 def initialize(dom, url) self.body = dom.at(css_path[:body]) self.items ||= {} self.url = url.sub('s2', 'searchPage') self.pages_count = self.body.at(css_path[:pages]).text.split('/')[1].to_i self.page = 1 process get_ajax(true) next_page end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
8 9 10 |
# File 'lib/mmonitor/strategies/yhd.rb', line 8 def body @body end |
#item ⇒ Object
Returns the value of attribute item.
8 9 10 |
# File 'lib/mmonitor/strategies/yhd.rb', line 8 def item @item end |
#items ⇒ Object
Returns the value of attribute items.
8 9 10 |
# File 'lib/mmonitor/strategies/yhd.rb', line 8 def items @items end |
#page ⇒ Object
Returns the value of attribute page.
8 9 10 |
# File 'lib/mmonitor/strategies/yhd.rb', line 8 def page @page end |
#pages_count ⇒ Object
Returns the value of attribute pages_count.
8 9 10 |
# File 'lib/mmonitor/strategies/yhd.rb', line 8 def pages_count @pages_count end |
#url ⇒ Object
Returns the value of attribute url.
8 9 10 |
# File 'lib/mmonitor/strategies/yhd.rb', line 8 def url @url end |
Instance Method Details
#css_path ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mmonitor/strategies/yhd.rb', line 26 def css_path { body: '#plist', list: '#itemSearchList', item: 'li.search_item > div.search_item_box', pages: '#rankOpDiv > div > div.select_page_num', # .text.split('/')[1] spu_id: 'pmid', title: 'p.title > a', photo_url: 'a.search_prod_img > img', # 'data-ks-lazyload' price: 'div.pricebox.clearfix > span:nth-child(1)' } end |
#pages ⇒ Object
分页伪装
49 50 51 |
# File 'lib/mmonitor/strategies/yhd.rb', line 49 def pages 1 end |
#photo_url ⇒ Object
产品图片
43 44 45 46 |
# File 'lib/mmonitor/strategies/yhd.rb', line 43 def photo_url # 产品图片 img = self.item.at(css_path[:photo_url]) img['original'] || img['src'] end |
#provider ⇒ Object
输出的产品
22 23 24 |
# File 'lib/mmonitor/strategies/yhd.rb', line 22 def provider :yhd end |
#spu_id ⇒ Object
产品图片
39 40 41 |
# File 'lib/mmonitor/strategies/yhd.rb', line 39 def spu_id # 产品图片 self.item.at(css_path[:title])[css_path[:spu_id]] end |