Class: ACLUScraper
- Inherits:
-
Object
- Object
- ACLUScraper
- Defined in:
- lib/acluscraper.rb
Instance Method Summary collapse
-
#initialize(url) ⇒ ACLUScraper
constructor
A new instance of ACLUScraper.
-
#scrapeCase ⇒ Object
Get all the case documents.
Constructor Details
#initialize(url) ⇒ ACLUScraper
Returns a new instance of ACLUScraper.
7 8 9 10 |
# File 'lib/acluscraper.rb', line 7 def initialize(url) @url = url @casearray = Array.new end |
Instance Method Details
#scrapeCase ⇒ Object
Get all the case documents
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/acluscraper.rb', line 13 def scrapeCase html = Nokogiri::HTML(open(@url)) prevdate = "" html.css("tbody").each do |t| t.css("tr").each do |r| if !r.css("a").empty? dochash = Hash.new # Get date for filing if r.css("td")[0].text == "\u00a0" dochash[:date] = prevdate else prevdate = r.css("td")[0].text.to_s dochash[:date] = r.css("td")[0].text.to_s end a = r.css("a") dochash[:title] = a.text # Get URL if a[0]["href"].to_s.include? "https://" dochash[:url] = a[0]["href"] else dochash[:url] = "https://www.aclu.org" + a[0]["href"] end # Download documents `wget -P public/uploads #{dochash[:url]}` path = dochash[:url].split("/") dochash[:path] = "public/uploads/" + path[path.length-1].chomp.strip # Extract metadata and text begin u = UploadConvert.new(dochash[:path]) = u.extractMetadataPDF .each{|k, v| dochash[k] = v} dochash[:text] = u.detectPDFType @casearray.push(dochash) rescue end end end end JSON.pretty_generate(@casearray) end |