Sha256: 44f99a2e205f096fdee9bc50f94ca36ce94014b4023a5e7477bbf1c94a4eaff6
Contents?: true
Size: 894 Bytes
Versions: 7
Compression:
Stored size: 894 Bytes
Contents
#!/usr/bin/env ruby ## sample app $:.unshift File.expand_path '../lib', File.dirname(__FILE__) require 'rubygems' require 'args_parser' parser = ArgsParser.parse ARGV do arg :url, 'URL', :alias => :u arg :output, 'output file', :alias => :o, :default => 'out.html' arg :verbose, 'verbose mode' arg :help, 'show help', :alias => :h filter :url do |v| v.to_s.strip end validate :url, "invalid URL" do |v| v =~ /^https?:\/\/.+$/ end end if parser.has_option? :help or !parser.has_param?(:url, :output) STDERR.puts "Download WebPage\n==" STDERR.puts parser.help STDERR.puts "e.g. ruby #{$0} -url http://example.com -o out.html" exit 1 end p parser require 'open-uri' puts 'download..' if parser[:verbose] data = open(parser[:url]).read puts data if parser[:verbose] open(parser[:output], 'w+') do |f| f.write data end puts "saved! => #{parser[:output]}"
Version data entries
7 entries across 7 versions & 1 rubygems