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.
19 20 21 22 |
# File 'lib/linkedin-scraper/profile.rb', line 19 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.
9 10 11 |
# File 'lib/linkedin-scraper/profile.rb', line 9 def linkedin_url @linkedin_url end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
9 10 11 |
# File 'lib/linkedin-scraper/profile.rb', line 9 def page @page end |
Class Method Details
Instance Method Details
#certifications ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/linkedin-scraper/profile.rb', line 116 def certifications @certifications ||= @page.search('ul.certifications/li.certification').map do |item| name = item.at('h3').text.gsub(/\s+|\n/, ' ').strip rescue nil = item.at('.specifics/.org').text.gsub(/\s+|\n/, ' ').strip rescue nil license = item.at('.specifics/.licence-number').text.gsub(/\s+|\n/, ' ').strip rescue nil start_date = item.at('.specifics/.dtstart').text.gsub(/\s+|\n/, ' ').strip rescue nil {:name => name, :authority => , :license => license, :start_date => start_date} end end |
#country ⇒ Object
44 45 46 |
# File 'lib/linkedin-scraper/profile.rb', line 44 def country @country ||= (@page.at('.locality').text.split(',').last.strip if @page.at('.locality')) end |
#current_companies ⇒ Object
68 69 70 |
# File 'lib/linkedin-scraper/profile.rb', line 68 def current_companies @current_companies ||= get_companies('current') end |
#education ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/linkedin-scraper/profile.rb', line 72 def education @education ||= @page.search('.position.education.vevent.vcard').map do |item| name = item.at('h3').text.gsub(/\s+|\n/, ' ').strip if item.at('h3') desc = item.at('h4').text.gsub(/\s+|\n/, ' ').strip if item.at('h4') period = item.at('.period').text.gsub(/\s+|\n/, ' ').strip if item.at('.period') {:name => name, :description => desc, :period => period} end end |
#first_name ⇒ Object
28 29 30 |
# File 'lib/linkedin-scraper/profile.rb', line 28 def first_name @first_name ||= (@page.at('.given-name').text.strip if @page.at('.given-name')) end |
#groups ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/linkedin-scraper/profile.rb', line 90 def groups @groups ||= @page.search('.group-data').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
48 49 50 |
# File 'lib/linkedin-scraper/profile.rb', line 48 def industry @industry ||= (@page.at('.industry').text.gsub(/\s+/, ' ').strip if @page.at('.industry')) end |
#languages ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/linkedin-scraper/profile.rb', line 108 def languages @languages ||= @page.search('ul.languages/li.language').map do |item| language = item.at('h3').text rescue nil proficiency = item.at('span.proficiency').text.gsub(/\s+|\n/, ' ').strip rescue nil {:language=> language, :proficiency => proficiency } end end |
#last_name ⇒ Object
32 33 34 |
# File 'lib/linkedin-scraper/profile.rb', line 32 def last_name @last_name ||= (@page.at('.family-name').text.strip if @page.at('.family-name')) end |
#location ⇒ Object
40 41 42 |
# File 'lib/linkedin-scraper/profile.rb', line 40 def location @location ||= (@page.at('.locality').text.split(',').first.strip if @page.at('.locality')) end |
#name ⇒ Object
24 25 26 |
# File 'lib/linkedin-scraper/profile.rb', line 24 def name "#{first_name} #{last_name}" end |
#organizations ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/linkedin-scraper/profile.rb', line 98 def organizations @organizations ||= @page.search('ul.organizations/li.organization').map do |item| name = item.search('h3').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
64 65 66 |
# File 'lib/linkedin-scraper/profile.rb', line 64 def past_companies @past_companies ||= get_companies('past') end |
#picture ⇒ Object
56 57 58 |
# File 'lib/linkedin-scraper/profile.rb', line 56 def picture @picture ||= (@page.at('#profile-picture/img.photo').attributes['src'].value.strip if @page.at('#profile-picture/img.photo')) end |
#recommended_visitors ⇒ Object
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/linkedin-scraper/profile.rb', line 129 def recommended_visitors @recommended_visitors ||= @page.search('.browsemap/.content/ul/li').map do |visitor| v = {} v[:link] = visitor.at('a')['href'] v[:name] = visitor.at('strong/a').text v[:title] = visitor.at('.headline').text.gsub('...',' ').split(' at ').first v[:company] = visitor.at('.headline').text.gsub('...',' ').split(' at ')[1] v end end |
#skills ⇒ Object
60 61 62 |
# File 'lib/linkedin-scraper/profile.rb', line 60 def skills @skills ||= (@page.search('.competency.show-bean').map{|skill| skill.text.strip if skill.text} rescue nil) end |
#summary ⇒ Object
52 53 54 |
# File 'lib/linkedin-scraper/profile.rb', line 52 def summary @summary ||= (@page.at('.description.summary').text.gsub(/\s+/, ' ').strip if @page.at('.description.summary')) end |
#title ⇒ Object
36 37 38 |
# File 'lib/linkedin-scraper/profile.rb', line 36 def title @title ||= (@page.at('.headline-title').text.gsub(/\s+/, ' ').strip if @page.at('.headline-title')) end |
#to_json ⇒ Object
140 141 142 143 |
# File 'lib/linkedin-scraper/profile.rb', line 140 def to_json require 'json' ATTRIBUTES.reduce({}){ |hash,attr| hash[attr.to_sym] = self.send(attr.to_sym);hash }.to_json end |
#websites ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/linkedin-scraper/profile.rb', line 82 def websites @websites ||= @page.search('.website').flat_map do |site| url = "http://www.linkedin.com#{site.at('a')['href']}" CGI.parse(URI.parse(url).query)['url'] end end |