-
-
Save abunsen/42f6327a6b1e654725f2d0cf600449c5 to your computer and use it in GitHub Desktop.
Craiglist Scrubber
This file contains hidden or 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
require "httparty" | |
require 'nokogiri' | |
homepage_url = "https://miami.craigslist.org/" | |
response1 = HTTParty.get homepage_url | |
home_page = Nokogiri::HTML(response1.body) | |
cats = [] | |
url_tag = [] | |
jobs = [] | |
joblinks = [] | |
home_page.css('ul#jjj0 li').each do |job_cat| | |
cats << job_cat | |
end | |
puts "Choose one to search:" | |
puts "*" * 20 | |
n=1 | |
cats.each do |cat| | |
puts ("#{n}: " + cat.content) | |
n += 1 | |
end | |
cat_select = (gets.chomp!.to_i - 1) | |
tag = cats[cat_select].children[0][:class] | |
if cat_select != 32 | |
jobs_url = "https://miami.craigslist.org/search/#{tag}" | |
else | |
jobs_url = "https://miami.craigslist.org/search/jjj?employment_type=2" | |
end | |
jobs_response = HTTParty.get jobs_url | |
job_page = Nokogiri::HTML(jobs_response.body) | |
# we only want jobs no other links | |
job_page.css('a.hdrlnk').each do |element| | |
jobs << element | |
end | |
# deleted a bunch of extra code | |
jobs.each do |j| | |
puts j.content | |
# ternary works like this: $statement ? something if $statement is true : something if $statement is false | |
puts (j[:href].include? "craigslist.org" ? "http:#{j[:href]}" : "https://miami.craigslist.org#{j[:href]}") | |
puts | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment