Class: LinkedinScraper::DuckDuckGo

Inherits:
Object
  • Object
show all
Defined in:
lib/linkedin/duck.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ DuckDuckGo

Returns a new instance of DuckDuckGo.

Raises:

  • ("TypeError")


7
8
9
10
11
# File 'lib/linkedin/duck.rb', line 7

def initialize options
  raise "TypeError", "Invalid Arguments" unless options.is_a? Hash
  @query = options[:query]
  @agent = Mechanize.new { |agent| agent.user_agent_alias = USER_AGENTS.sample }
end

Instance Method Details

#searchObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/linkedin/duck.rb', line 13

def search
  output_arr = []
  query_to_url
  previous_content = ""
  page = @agent.get("http:\/\/duckduckgo.com\/d.js?q=#{@query}&l=us-en&p=1&s=0")
  content = page.content.match(/\[.*\]/).to_s
  raise "No Profile, Profile not found or does not exist" if (content.nil? || content.empty?)
  output_arr = JSON.parse(content).map {|f| f['c'] }
  output_arr = output_arr.flatten.uniq
  output_arr.each do |f| 
    next unless f
    output_arr.delete(f) if f.include? "https://encrypted.google.com"
    output_arr.delete(f) if f == nil
  end
  output_arr
end