Class: Xunlei::Search
- Inherits:
-
Object
- Object
- Xunlei::Search
- Defined in:
- lib/xunlei/search.rb
Instance Method Summary collapse
- #add_page(page_url, options) ⇒ Object
- #google(keywords, options) ⇒ Object
- #google_simplecd(keywords, options) ⇒ Object
-
#initialize(driver = :chrome) ⇒ Search
constructor
A new instance of Search.
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, ) 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 !.only.nil? links << link if link =~ /#{options.only}/i elsif !.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, ) do_google(keywords, , "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, ) do_google(keywords, , "http://www.google.com/search?q=site:simplecd.org+", 1) end |