Skip to content

Instantly share code, notes, and snippets.

@frankolson
Created July 14, 2018 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frankolson/6af85f298c0ce5ec245c669bede3515b to your computer and use it in GitHub Desktop.
Save frankolson/6af85f298c0ce5ec245c669bede3515b to your computer and use it in GitHub Desktop.
Grab the list of LinkedIn industries.
# Updated version of the following gist:
# https://gist.github.com/stevenzeiler/1895583
#
# list = Linkedin::IndustryList.new
# industry = list.industries.first
#
# industry.description
# => "Accounting"
#
# industry.code
# => 47
#
# industry.groups
# => ["corp", "fin"]
require 'nokogiri'
require 'open-uri'
module Linkedin
class IndustryList
attr_reader :industries
def initialize
@industries = scrape_linkedin
end
def scrape_linkedin
industries = []
doc = Nokogiri::HTML open('https://developer.linkedin.com/docs/reference/industry-codes')
doc.search('.resourceTable tr').each do |tr|
industry = Industry.new(tr.children)
industries << industry if industry.valid?
end
industries
end
end
class Industry
attr_reader :code, :groups, :description
def initialize(tds)
return if ['Code', '', ' ', nil].include? tds.first.text
@code = tds[0].text.to_i
@groups = tds[2].text.split(', ')
@description = tds[4].text
@valid = true
end
def valid?
@valid
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment