Class: Spider::JiYing

Inherits:
Common
  • Object
show all
Defined in:
lib/spider_rails/ji_ying.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Common

#full_site_filter, #get_content

Constructor Details

#initialize(page) ⇒ JiYing

Returns a new instance of JiYing.



5
6
7
8
9
# File 'lib/spider_rails/ji_ying.rb', line 5

def initialize page
  @ani = Hash.new
  @anis = Array.new
  @page = page
end

Instance Attribute Details

#aniObject

Returns the value of attribute ani.



3
4
5
# File 'lib/spider_rails/ji_ying.rb', line 3

def ani
  @ani
end

#anisObject

Returns the value of attribute anis.



3
4
5
# File 'lib/spider_rails/ji_ying.rb', line 3

def anis
  @anis
end

Instance Method Details

#final_pageObject



22
23
24
# File 'lib/spider_rails/ji_ying.rb', line 22

def final_page
  @page.element(css: '.title h2 a').text[/\(.+\)/].gsub!(/\(|\)/, '').to_i/100 + 1
end

#full_page(page_num) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/spider_rails/ji_ying.rb', line 26

def full_page page_num
  @page.goto "http://bt.ktxp.com/search.php?keyword=%E8%AF%B8%E7%A5%9E&sort_id=28&field=title&order=&page=#{page_num}"
  html = Nokogiri::HTML.parse @page.html
  html.css('.ltext').each do |td|
    single(td)
  end
end

#full_siteObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/spider_rails/ji_ying.rb', line 11

def full_site
  fp = final_page
  begin
    (1..fp).each do |page_num|
      full_page page_num
    end
    #rescue Exception
    #  raise %Q(page isn't not exist)
  end
end

#get(element) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/spider_rails/ji_ying.rb', line 39

def get(element)
  element.css('a.quick-down').each do |a|
    @ani[:torrent] = a['href']
  end
  element.css('a.quick-down+a').each do |a|
    @ani[:title] = a.content
  end
  @ani
end

#single(element) ⇒ Object



34
35
36
37
# File 'lib/spider_rails/ji_ying.rb', line 34

def single element
  get(element)
  @anis << single_filter
end

#single_filterObject



49
50
51
52
53
54
55
56
57
# File 'lib/spider_rails/ji_ying.rb', line 49

def single_filter
  if @ani[:title][/外挂/u]
    @ani[:torrent].prepend('http://bt.ktxp.com') if @ani[:torrent]
  else
    @ani[:title] = nil
  end

  @ani if @ani
end