Created
July 14, 2018 00:04
-
-
Save frankolson/6af85f298c0ce5ec245c669bede3515b to your computer and use it in GitHub Desktop.
Grab the list of LinkedIn industries.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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