-
-
Notifications
You must be signed in to change notification settings - Fork 897
/
nokogiri
executable file
·47 lines (39 loc) · 940 Bytes
/
nokogiri
1
2
3
4
5
6
7
8
9
10
11
12
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
#!/usr/bin/env ruby
require 'optparse'
require 'open-uri'
require 'irb'
require 'uri'
require 'rubygems'
require 'nokogiri'
opts = OptionParser.new do |opts|
opts.banner = "Nokogiri: an HTML, XML, SAX, and Reader parser"
opts.define_head "Usage: nokogiri <uri|path> [options]"
opts.separator ""
opts.separator "Examples:"
opts.separator " nokogiri http://www.ruby-lang.org/"
opts.separator " nokogiri ./public/index.html"
opts.separator ""
opts.separator "Options:"
opts.on_tail("-?", "--help", "Show this message") do
puts opts
exit
end
opts.on_tail("-v", "--version", "Show version") do
require 'yaml'
puts Nokogiri::VERSION_INFO.to_yaml
exit
end
end
opts.parse!
uri = ARGV.shift
if uri.to_s.strip.empty?
puts opts
exit 1
end
if URI.parse(uri).scheme
@doc = Nokogiri(open(uri).read)
else
@doc = Nokogiri(File.read(uri))
end
puts "Your document is stored in @doc..."
IRB.start