Sha256: dc368eaaa62c7001e845b968371b56f560039ae108415223fd5c10ec0428c841

Contents?: true

Size: 757 Bytes

Versions: 4

Compression:

Stored size: 757 Bytes

Contents

#!/usr/bin/env ruby
require 'rubygems'
require 'args_parser'
## require File.dirname(__FILE__)+'/../lib/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
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

4 entries across 4 versions & 1 rubygems

Version Path
args_parser-0.0.4 samples/download_webpage.rb
args_parser-0.0.3 samples/download_webpage.rb
args_parser-0.0.2 samples/download_webpage.rb
args_parser-0.0.1 samples/download_webpage.rb