-
Notifications
You must be signed in to change notification settings - Fork 0
/
apartment_scrapper.rb
38 lines (28 loc) · 1.18 KB
/
apartment_scrapper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class ApartmentScrapper
def self.scrape(urls = [])
urls.each { |url| new(url).scrape }
end
def initialize(url)
@url = url
end
def apartment_elements
@apartment_elements ||= regular_apartment_elements + vauvau_apartment_elements
end
private
attr_reader :url
def response_body
@response_body ||= HTTParty.get(url)
end
def response_document
@response_document ||= Oga.parse_html(response_body)
end
def regular_apartment_elements
@regular_apartment_elements ||= response_document.xpath('//div[contains(@class, "content-main")]/div[contains(@class, "block-standard")]/div[contains(@class, "EntityList--Regular")]/ul[contains(@class, "EntityList-items")]/li[contains(@class, "EntityList-item--Regular")]')
end
def vauvau_apartment_elements
@vauvau_apartment_elements ||= response_document.xpath('//div[contains(@class, "content-main")]/div[contains(@class, "block-standard")]/div[contains(@class, "EntityList--VauVau")]/ul[contains(@class, "EntityList-items")]/li[contains(@class, "EntityList-item--VauVau")]')
end
# def apartments
# @apartments ||= apartment_elements.map {|apartment_element| Apartment.new(apartment_element)}
# end
end