lib/linkedin-scraper/profile.rb in linkedin-scraper-0.1.3 vs lib/linkedin-scraper/profile.rb in linkedin-scraper-0.1.5
- old
+ new
@@ -3,11 +3,31 @@
class Profile
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)
+ 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)
attr_reader :page, :linkedin_url
def self.get_profile(url)
Linkedin::Profile.new(url)
@@ -93,13 +113,13 @@
{ :name => name, :link => link }
end
end
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 ')
+ @organizations ||= @page.search('#background-organizations .section-item').map do |item|
+ name = item.at('.summary').text.gsub(/\s+|\n/, ' ').strip rescue nil
+ start_date, end_date = item.at('.organizations-date').text.gsub(/\s+|\n/, ' ').strip.split(' – ') rescue nil
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
@@ -147,19 +167,17 @@
if @page.search(".background-experience .#{type}-position").first
@page.search(".background-experience .#{type}-position").each do |node|
company = {}
company[:title] = node.at('h4').text.gsub(/\s+|\n/, ' ').strip if node.at('h4')
- company[:company] = node.at('h5').text.gsub(/\s+|\n/, ' ').strip if node.at('h5')
+ company[:company] = node.at('h4').next.text.gsub(/\s+|\n/, ' ').strip if node.at('h4').next
company[:description] = node.at(".description").text.gsub(/\s+|\n/, ' ').strip if node.at(".description")
- start_date = node.at('.dtstart')['title'] rescue nil
+ start_date, end_date = node.at('.experience-date-locale').text.strip.split(" – ") rescue nil
company[:start_date] = parse_date(start_date) rescue nil
-
- end_date = node.at('.dtend')['title'] rescue nil
company[:end_date] = parse_date(end_date) rescue nil
- company_link = node.at('h5/a')['href'] if node.at('h5/a')
+ company_link = node.at('h4').next.at('a')['href'] if node.at('h4').next.at('a')
result = get_company_details(company_link)
companies << company.merge!(result)
end
end