Skip to content

Instantly share code, notes, and snippets.

@aosalias
Created March 3, 2016 21:34
Show Gist options
  • Select an option

  • Save aosalias/688ccae205488add42ad to your computer and use it in GitHub Desktop.

Select an option

Save aosalias/688ccae205488add42ad to your computer and use it in GitHub Desktop.
require 'mechanize'
class Job
attr_accessor :title, :location
def initialize(title:, location:)
@title = title
@location = location
end
def to_s
"#{@title} #{@location}"
end
end
a = Mechanize.new { |agent|
agent.user_agent_alias = 'Mac Safari'
}
jobs = []
a.get('https://www.gapinctalent.com/oldnavy/landingpages/tienda-ventasexistenciasliderazgo-opportunities-at-old-navy-33') do |page|
page.links_with(class: 'learn_more_btn').first(2).each do |job_link|
job_page = job_link.click
puts job_page.search('h1.title').text.strip
puts job_page.search('.primary_location a').text.strip
j = Job.new(
title: job_page.search('h1.title').text.strip,
location: job_page.search('.primary_location a').text.strip
)
jobs.push(j)
end
end
puts jobs.map(&:to_s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment