Class: LocalRealEstate::Scraper
- Inherits:
-
Object
- Object
- LocalRealEstate::Scraper
- Defined in:
- lib/local_real_estate/scraper.rb
Overview
Each Indoc.css(‘.srp-item-body’)
Instance Attribute Summary collapse
-
#zip ⇒ Object
Returns the value of attribute zip.
Instance Method Summary collapse
- #create_listings ⇒ Object
- #expand_listing(index) ⇒ Object
-
#get_page ⇒ Object
this needs to be fixed.
-
#initialize(zip) ⇒ Scraper
constructor
A new instance of Scraper.
- #scrape_listings ⇒ Object
Constructor Details
#initialize(zip) ⇒ Scraper
Returns a new instance of Scraper.
10 11 12 |
# File 'lib/local_real_estate/scraper.rb', line 10 def initialize(zip) @zip = zip end |
Instance Attribute Details
#zip ⇒ Object
Returns the value of attribute zip.
8 9 10 |
# File 'lib/local_real_estate/scraper.rb', line 8 def zip @zip end |
Instance Method Details
#create_listings ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# 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) ⇒ Object
38 39 40 |
# File 'lib/local_real_estate/scraper.rb', line 38 def (index) LocalRealEstate::Listing end |
#get_page ⇒ Object
this needs to be fixed. If zip starts with zero its lost with .to_i
14 15 16 |
# 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 ⇒ Object
18 19 20 |
# File 'lib/local_real_estate/scraper.rb', line 18 def scrape_listings self.get_page.css('.srp-item-body') end |