-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.rb
23 lines (20 loc) · 1 KB
/
parser.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ruby-2.2.6-p396
URL = '' # you desired url
require 'nokogiri' # gem install nokogiri
require 'open-uri' # already part of your ruby install
require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE # Don't use it in production environment
# open the html document and target only the links, <a href="...">
Nokogiri::HTML(open(URL)).xpath("//a/@href").each do |href|
uri = URI.join( URL, href ).to_s # make absolute uri
if uri.end_with?('') # insert you desired file ending inside the quotes, you can use "" as well
puts "Downloading: " + uri
File.open(File.basename(uri),'wb'){ |f| f.write(open(uri).read) }
elsif uri.end_with?('') # insert you desired file ending inside the quotes
puts "Downloading: " + uri
File.open(File.basename(uri),'wb'){ |f| f.write(open(uri).read) }
elsif uri.end_with?('') # insert you desired file ending inside the quotes
puts "Downloading: " + uri
File.open(File.basename(uri),'wb'){ |f| f.write(open(uri).read) }
end
end