Class: LoyalSpider::Clients::KuaileMahua::ArticleEntity

Inherits:
Object
  • Object
show all
Includes:
EntityAble, FetchAble
Defined in:
lib/loyal_spider/clients/kuaile_mahua/article_entity.rb

Instance Method Summary collapse

Methods included from FetchAble

included

Methods included from EntityAble

included

Instance Method Details

#after_fetch_success(result) ⇒ Object

TODO



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/loyal_spider/clients/kuaile_mahua/article_entity.rb', line 15

def after_fetch_success result
  # puts "after_fetch success: #{result}"
  html_doc = result.response_html_doc
  entity_doc = html_doc.css('.main .main-left .xiaohua .xiaohua-data')

  self.title = entity_doc.css('h1').first.text.to_s.strip
  self.content = entity_doc.css('.content').inner_html
  self.tags = entity_doc.css('.link .tags h4 a').map do |_tag_doc|
    {
      :text => _tag_doc.text.to_s.strip,
      :href => "#{self.base_url}#{_tag_doc.attr('href').to_s.strip}"
    }
  end

  self.authors = entity_doc.css('.link .tags .pusher a').map do |_author_doc|
    {
      :text => _author_doc.text.to_s.strip,
      :href => "#{_author_doc.attr('href').to_s.strip}"
    }
  end

  self.up_rating      = entity_doc.css('.tools li a.good').text.to_i
  self.down_rating    = entity_doc.css('.tools li a.bad').text.to_i
  self.comments_count = entity_doc.css('.tools li s').first.text.to_i

end