Class: Ish::Crawler

Inherits:
Object
  • Object
show all
Defined in:
lib/ish/crawler.rb

Class Method Summary collapse

Class Method Details

.google_first_result(text) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ish/crawler.rb', line 4

def self.google_first_result text
  result = HTTParty.get( "https://www.google.com/search?q=#{text}", :verify => false )
  r = Nokogiri::HTML(result.body)
  website = r.css('cite')[0].text
  website = "https://#{website}" unless website[0..3] == 'http'

  begin
    r = HTTParty.get( website, :verify => false )
  rescue OpenSSL::SSL::SSLError => e
    return { :url => website }
  end

  return { :url => website, :html => r.body }
end

.look_for_emails(text) ⇒ Object


19
20
21
22
23
# File 'lib/ish/crawler.rb', line 19

def self.look_for_emails text
  email_regex = /\A[\w+\-.][email protected][a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
  result = text.scan( email_regex )
  return result.length > 0 ? result.join(',') : nil
end