class Scraper

Attributes

encoded_url[RW]
product_rows[RW]
query[RW]

Public Class Methods

new(query_object) click to toggle source
# File lib/scraper.rb, line 5
def initialize(query_object)
  self.query = query_object
  self.product_rows = []
end

Public Instance Methods

htmlify(string) click to toggle source
# File lib/scraper.rb, line 10
def htmlify(string)
  string.gsub(" ", "+")
end
number_extraction() click to toggle source
# File lib/scraper.rb, line 23
def number_extraction
    self.product_rows.map do |product_row|
      product_row.css('span.l2 span.price').text[1..-1].to_i
  end
end
open_url() click to toggle source
# File lib/scraper.rb, line 29
def open_url # in development, not implemented
  `open #{self.encoded_url}`
end
scrape() click to toggle source
# File lib/scraper.rb, line 14
def scrape
  self.encoded_url = URI.encode("https://newyork.craigslist.org/search/sss#{query.keyword_to_url}?zoomToPosting=&catAbb=sss&query=#{htmlify(query.search_query)}&minAsk=#{query.min_price}&maxAsk=#{query.max_price}&sort=rel&excats=")
  html = open(URI.parse(self.encoded_url)) # /sss?zo
  cl_page = Nokogiri::HTML(html.read)
  cl_page.css('div.content p.row').map do |product_row|
    self.product_rows << product_row
  end
end