Class: LoyalSpider::Clients::Xiaohuadi::ArticleEntityLister
- Inherits:
-
Object
- Object
- LoyalSpider::Clients::Xiaohuadi::ArticleEntityLister
- Includes:
- EntityListerAble
- Defined in:
- lib/loyal_spider/clients/xiaohuadi/article_entity_lister.rb
Instance Method Summary collapse
- #after_fetch_fail(result) ⇒ Object
-
#after_fetch_success(result) ⇒ Object
TODO.
-
#before_fetch(options = {}) ⇒ Object
TODO:.
Methods included from EntityListerAble
Instance Method Details
#after_fetch_fail(result) ⇒ Object
88 89 90 |
# File 'lib/loyal_spider/clients/xiaohuadi/article_entity_lister.rb', line 88 def after_fetch_fail result puts "after_fetch fail: #{result}" end |
#after_fetch_success(result) ⇒ Object
TODO
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/loyal_spider/clients/xiaohuadi/article_entity_lister.rb', line 22 def after_fetch_success result # puts "after_fetch success: #{result}" html_doc = result.response_html_doc html_doc.css('.ilistxllist>ul').each do |entity_doc| _entity_attr = {} = result. _base_url = .base_url.to_s.strip # :content # 正文 # :tags # 标签 # :up_rating # 好评数 # :down_rating # 差评数目 # :comments_count # 评论数目 # :authors # 抓取的作者信息 _link_doc = entity_doc.css('.ilistxlctlB1 a') _entity_attr[:url] = "#{_base_url}#{_link_doc.attr('href')}" _entity_attr[:title] = "#{_link_doc.text}" _text_content = entity_doc.css('.ilistxlctlB2').first.inner_html _content = _text_content.split("<br>\r\n").map do |_cnt| "<p>#{Sanitize.clean _cnt}</p>" end.join('') _entity_attr[:content] = _content _category_doc = entity_doc.css('.ilistxlctlC table td a').last if _category_doc _entity_attr[:tags] = [ { :text => _category_doc.text, :href => "#{self.base_url}#{_category_doc.attr('href')}" } ] else _entity_attr[:tags] = [] end _entity_attr[:authors] = [] _tool_doc = entity_doc.css('.ilistxlctlA ul li') _entity_attr[:up_rating] = _tool_doc[1].text.to_i _entity_attr[:down_rating] = _tool_doc[2].text.to_i _entity_attr[:comments_count] = _tool_doc[0].text.to_i _entity = self.new_entity(_entity_attr) if _entity.content.include?('未显示完,查看全文') _entity.fetch end if _entity.valid? self.add_entity _entity end end # debugger end |
#before_fetch(options = {}) ⇒ Object
TODO:
17 18 19 |
# File 'lib/loyal_spider/clients/xiaohuadi/article_entity_lister.rb', line 17 def before_fetch ={} puts "before_fetch: #{}" end |