lib/ImageScraper.rb in ImageScraper-0.0.1 vs lib/ImageScraper.rb in ImageScraper-0.0.2
- old
+ new
@@ -4,27 +4,39 @@
module ImageScraper
#The constructor
def self.initialize(url, folder = "Images")
- if url[url.length] != "/"
- url += "/"
- end
@url = url
@folder = folder
end
#A function to get HTML of page at a url
def self.getPage()
@page = Nokogiri::HTML(open(@url).read)
end
- #a method to get image links
+
+ def self.getNewUrl()
+ new_url = /([a-z0-9]|_)+.(html)|(php)$/.match(@url)
+ puts new_url.to_s
+ n = new_url.to_s
+ return @url.slice! n
+ end
+
+ #A method to get image links
def self.getImgLinks()
img = @page.css('img')
@imgLinks = Array.new
+ new_url = self.getNewUrl()
+
+ if @url[@url.length-1] != '/'
+ @url += "/"
+ end
+ print new_url
+
img.each do |i|
@imgLinks.push(@url+i["src"])
end
end
@@ -55,11 +67,12 @@
@files.push(@folder + "/" + nodes[nodes.length - 1])
end
end
#A method to download all files at a given url
- def self.Scrape()
+ def self.Scrap()
self.getPage
+ puts "Page Found"
self.getImgNames
self.getImgLinks
self.download
end