class LocalRealEstate::Scraper

Each Indoc.css('.srp-item-body')

Attributes

zip[RW]

Public Class Methods

new(zip) click to toggle source
# File lib/local_real_estate/scraper.rb, line 10
def initialize(zip)
  @zip = zip
end

Public Instance Methods

create_listings() click to toggle source
# File lib/local_real_estate/scraper.rb, line 22
def create_listings
  scrape_listings.each_with_index do |object, index|
    LocalRealEstate::Listing.new(
      address: object.css('.listing-street-address').text.strip,
      city: object.css('.listing-city').text,
      state: object.css('.listing-region').text,
      price: object.css('.srp-item-price').text.strip,
      bedrooms: object.css("ul li[data-label='property-meta-beds']").text,
      bathrooms: object.css("ul li[data-label='property-meta-baths']").text,
      sqft: object.css("ul li[data-label='property-meta-sqft']").text,
      cars: object.css("ul li[data-label='property-meta-garage']").text,
      lot_size: object.css("ul li[data-label='property-meta-lotsize']").text
    )
  end
end
expand_listing(index) click to toggle source
# File lib/local_real_estate/scraper.rb, line 38
def expand_listing(index)
  LocalRealEstate::Listing
end
get_page() click to toggle source
# File lib/local_real_estate/scraper.rb, line 14
def get_page #this needs to be fixed. If zip starts with zero its lost with .to_i
  Nokogiri::HTML(open("https://www.realtor.com/realestateandhomes-search/#{@zip}"))
end
scrape_listings() click to toggle source
# File lib/local_real_estate/scraper.rb, line 18
def scrape_listings
  self.get_page.css('.srp-item-body')
end