Class: UqLibraries::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/uq_libraries/scraper.rb

Constant Summary collapse

@@base_url =

URL without page

"https://www.library.uq.edu.au/uqlsm/"
@@main_page =

Page to append to URL

"availablepcsembed.php"
@@main_url =

Adds page and URL together

"#{@@base_url}#{@@main_page}"

Class Method Summary collapse

Class Method Details

.scrape_details_page(library_url) ⇒ Object

Scrapes library details page for secondary details



26
27
28
29
30
31
32
33
# File 'lib/uq_libraries/scraper.rb', line 26

def self.scrape_details_page(library_url) # Scrapes library details page for secondary details
    details_page = Nokogiri::HTML(open(library_url))

    details_page.css("table.chart tr").collect do |level|
        right = level.css(".right").text.split
        {level: level.css(".left").text, available: right[0], out_of_available: right[3]}
    end
end

.scrape_main_pageObject

Scrapes the main libraries page for primary details



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/uq_libraries/scraper.rb', line 8

def self.scrape_main_page # Scrapes the main libraries page for primary details
    libraries = []
    frontpage = Nokogiri::HTML(open(@@main_url))

    frontpage.css(".chart tr").each do |row|
        name = row.css("a[href]").text

        total_available = row.css(".right").text.split(" ")[0]
        out_of_available = row.css(".right").text.split(" ")[3]

        library_page = row.css("a[href]")[0]["href"]
        library_url = "#{@@base_url}#{library_page}"

        libraries << {name: name, total_available: total_available, total_out_of_available: out_of_available, library_url: library_url}
    end
    libraries
end