Class: Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/indeed_scraper/scraper.rb

Constant Summary collapse

BASE_PATH =
"https://www.indeed.com"

Class Method Summary collapse

Class Method Details

.scrape_index_page(input) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/indeed_scraper/scraper.rb', line 5

def self.scrape_index_page(input)
  html = open(BASE_PATH + "/l-#{input}-jobs.html") # interpolate input
  parsed_page = Nokogiri::HTML(html)
  all_jobs = parsed_page.css('div.jobsearch-SerpJobCard')

  all_jobs.collect do |job_card|
    job = {
      :title => job_card.css('a').attr('title').value,
      :company => job_card.css('span.company').text.strip, #remove white space
      :location => job_card.css('div.location').text,
      :job_url => job_card.css('a').attr('href').value,
      :salary => job_card.css('span.salary').text.strip,
      :description => job_card.css('span.summary').text.strip
    }
    job
  end
end