Class: Xunlei::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/xunlei/search.rb

Instance Method Summary collapse

Constructor Details

#initialize(driver = :chrome) ⇒ Search



7
8
# File 'lib/xunlei/search.rb', line 7

def initialize(driver = :chrome)
end

Instance Method Details

#add_page(page_url, options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/xunlei/search.rb', line 18

def add_page(page_url, options)
  doc = Nokogiri::HTML(open(page_url) { |page| page.read })
  links = []
  
  doc.css("a").select do |a|
    !a['href'].nil? && a['href'] =~ /ed2k:|magnet:/
  end.map do |a|
    a['href']
  end.uniq.each do |link|
    if !options.only.nil?
      links << link if link =~ /#{options.only}/i
    elsif !options.except.nil?
      links << link unless link =~ /#{options.except}/i
    else
      links << link
    end
  end
  links.each { |link| puts link }
  links
end

#google(keywords, options) ⇒ Object



10
11
12
# File 'lib/xunlei/search.rb', line 10

def google(keywords, options)
  do_google(keywords, options, "http://www.google.com/search?q=", 10)
end

#google_simplecd(keywords, options) ⇒ Object



14
15
16
# File 'lib/xunlei/search.rb', line 14

def google_simplecd(keywords, options)
  do_google(keywords, options, "http://www.google.com/search?q=site:simplecd.org+", 1)
end