Class: Linkedin::Profile
- Inherits:
-
Object
- Object
- Linkedin::Profile
- Defined in:
- lib/linkedin-scraper/profile.rb
Constant Summary collapse
- USER_AGENTS =
['Windows IE 6', 'Windows IE 7', 'Windows Mozilla', 'Mac Safari', 'Mac FireFox', 'Mac Mozilla', 'Linux Mozilla', 'Linux Firefox', 'Linux Konqueror']
- ATTRIBUTES =
%w(name first_name last_name title location country industry summary picture linkedin_url education groups websites languages skills certifications organizations past_companies current_companies recommended_visitors)
Instance Attribute Summary collapse
-
#linkedin_url ⇒ Object
readonly
Returns the value of attribute linkedin_url.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Class Method Summary collapse
Instance Method Summary collapse
- #certifications ⇒ Object
- #country ⇒ Object
- #current_companies ⇒ Object
- #education ⇒ Object
- #first_name ⇒ Object
- #groups ⇒ Object
- #industry ⇒ Object
-
#initialize(url) ⇒ Profile
constructor
A new instance of Profile.
- #languages ⇒ Object
- #last_name ⇒ Object
- #location ⇒ Object
- #name ⇒ Object
- #organizations ⇒ Object
- #past_companies ⇒ Object
- #picture ⇒ Object
- #recommended_visitors ⇒ Object
- #skills ⇒ Object
- #summary ⇒ Object
- #title ⇒ Object
- #to_json ⇒ Object
- #websites ⇒ Object
Constructor Details
#initialize(url) ⇒ Profile
Returns a new instance of Profile.
18 19 20 21 |
# File 'lib/linkedin-scraper/profile.rb', line 18 def initialize(url) @linkedin_url = url @page = http_client.get(url) end |
Instance Attribute Details
#linkedin_url ⇒ Object (readonly)
Returns the value of attribute linkedin_url.
10 11 12 |
# File 'lib/linkedin-scraper/profile.rb', line 10 def linkedin_url @linkedin_url end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
10 11 12 |
# File 'lib/linkedin-scraper/profile.rb', line 10 def page @page end |
Class Method Details
Instance Method Details
#certifications ⇒ Object
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/linkedin-scraper/profile.rb', line 115 def certifications @certifications ||= @page.search('background-certifications').map do |item| name = item.at('h4').text.gsub(/\s+|\n/, ' ').strip rescue nil = item.at('h5').text.gsub(/\s+|\n/, ' ').strip rescue nil license = item.at('.specifics/.licence-number').text.gsub(/\s+|\n/, ' ').strip rescue nil start_date = item.at('.certification-date').text.gsub(/\s+|\n/, ' ').strip rescue nil { :name => name, :authority => , :license => license, :start_date => start_date } end end |
#country ⇒ Object
43 44 45 |
# File 'lib/linkedin-scraper/profile.rb', line 43 def country @country ||= (@page.at('.locality').text.split(',').last.strip if @page.at('.locality')) end |
#current_companies ⇒ Object
67 68 69 |
# File 'lib/linkedin-scraper/profile.rb', line 67 def current_companies @current_companies ||= get_companies('current') end |
#education ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/linkedin-scraper/profile.rb', line 71 def education @education ||= @page.search('.background-education .education').map do |item| name = item.at('h4').text.gsub(/\s+|\n/, ' ').strip if item.at('h4') desc = item.at('h5').text.gsub(/\s+|\n/, ' ').strip if item.at('h5') period = item.at('.education-date').text.gsub(/\s+|\n/, ' ').strip if item.at('.education-date') {:name => name, :description => desc, :period => period } end end |
#first_name ⇒ Object
27 28 29 |
# File 'lib/linkedin-scraper/profile.rb', line 27 def first_name @first_name ||= (@page.at('.full-name').text.split(' ', 2)[0].strip if @page.at('.full-name')) end |
#groups ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/linkedin-scraper/profile.rb', line 89 def groups @groups ||= @page.search('.groups-name').map do |item| name = item.text.gsub(/\s+|\n/, ' ').strip link = "http://www.linkedin.com#{item.at('a')['href']}" { :name => name, :link => link } end end |
#industry ⇒ Object
47 48 49 |
# File 'lib/linkedin-scraper/profile.rb', line 47 def industry @industry ||= (@page.at('.industry').text.gsub(/\s+/, ' ').strip if @page.at('.industry')) end |
#languages ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/linkedin-scraper/profile.rb', line 107 def languages @languages ||= @page.search('.background-languages #languages ol li').map do |item| language = item.at('h4').text rescue nil proficiency = item.at('div.languages-proficiency').text.gsub(/\s+|\n/, ' ').strip rescue nil { :language => language, :proficiency => proficiency } end end |
#last_name ⇒ Object
31 32 33 |
# File 'lib/linkedin-scraper/profile.rb', line 31 def last_name @last_name ||= (@page.at('.full-name').text.split(' ', 2)[1].strip if @page.at('.full-name')) end |
#location ⇒ Object
39 40 41 |
# File 'lib/linkedin-scraper/profile.rb', line 39 def location @location ||= (@page.at('.locality').text.split(',').first.strip if @page.at('.locality')) end |
#name ⇒ Object
23 24 25 |
# File 'lib/linkedin-scraper/profile.rb', line 23 def name "#{first_name} #{last_name}" end |
#organizations ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/linkedin-scraper/profile.rb', line 97 def organizations @organizations ||= @page.search('.background-organizations .organization p a').map do |item| name = item.text.gsub(/\s+|\n/, ' ').strip rescue nil start_date, end_date = item.search('ul.specifics li').text.gsub(/\s+|\n/, ' ').strip.split(' to ') start_date = Date.parse(start_date) rescue nil end_date = Date.parse(end_date) rescue nil { :name => name, :start_date => start_date, :end_date => end_date } end end |
#past_companies ⇒ Object
63 64 65 |
# File 'lib/linkedin-scraper/profile.rb', line 63 def past_companies @past_companies ||= get_companies('past') end |
#picture ⇒ Object
55 56 57 |
# File 'lib/linkedin-scraper/profile.rb', line 55 def picture @picture ||= (@page.at('.profile-picture img').attributes['src'].value.strip if @page.at('.profile-picture img')) end |
#recommended_visitors ⇒ Object
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/linkedin-scraper/profile.rb', line 127 def recommended_visitors @recommended_visitors ||= @page.search('.insights-browse-map/ul/li').map do |visitor| v = {} v[:link] = visitor.at('a')['href'] v[:name] = visitor.at('h4/a').text v[:title] = visitor.at('.browse-map-title').text.gsub('...', ' ').split(' at ').first v[:company] = visitor.at('.browse-map-title').text.gsub('...', ' ').split(' at ')[1] v end end |
#skills ⇒ Object
59 60 61 |
# File 'lib/linkedin-scraper/profile.rb', line 59 def skills @skills ||= (@page.search('.skill-pill .endorse-item-name-text').map { |skill| skill.text.strip if skill.text } rescue nil) end |
#summary ⇒ Object
51 52 53 |
# File 'lib/linkedin-scraper/profile.rb', line 51 def summary @summary ||= (@page.at('.summary .description').text.gsub(/\s+/, ' ').strip if @page.at('.summary .description')) end |
#title ⇒ Object
35 36 37 |
# File 'lib/linkedin-scraper/profile.rb', line 35 def title @title ||= (@page.at('.title').text.gsub(/\s+/, ' ').strip if @page.at('.title')) end |
#to_json ⇒ Object
138 139 140 141 |
# File 'lib/linkedin-scraper/profile.rb', line 138 def to_json require 'json' ATTRIBUTES.reduce({}){ |hash,attr| hash[attr.to_sym] = self.send(attr.to_sym);hash }.to_json end |
#websites ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/linkedin-scraper/profile.rb', line 81 def websites @websites ||= @page.search('#overview-summary-websites').flat_map do |site| url = "http://www.linkedin.com#{site.at('a')['href']}" CGI.parse(URI.parse(url).query)['url'] end end |