Class: Ronin::Web::CLI::Commands::Xml Private
- Inherits:
-
Ronin::Web::CLI::Command
- Object
- Core::CLI::Command
- Ronin::Web::CLI::Command
- Ronin::Web::CLI::Commands::Xml
- Defined in:
- lib/ronin/web/cli/commands/xml.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Performs XPath queries on a URL or XML file.
Usage
ronin-web xml [options] {URL | FILE} [XPATH]
Options
-X, --xpath XPATH XPath query
-t, --text Prints the inner-text
-F, --first Only print the first match
-h, --help Print help information
Arguments
URL | FILE The URL or FILE to search
XPATH The XPath query
Direct Known Subclasses
Instance Attribute Summary collapse
-
#query ⇒ String?
readonly
private
The XPath expression.
Instance Method Summary collapse
-
#parse(html) ⇒ Nokogiri::XML::Document
private
Parses the HTML source code.
-
#read(source) ⇒ File, String
private
Reads a URI or file.
-
#run(source, query = @query) ⇒ Object
private
Runs the
ronin-web xml
command.
Instance Attribute Details
#query ⇒ String? (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The XPath expression.
85 86 87 |
# File 'lib/ronin/web/cli/commands/xml.rb', line 85 def query @query end |
Instance Method Details
#parse(html) ⇒ Nokogiri::XML::Document
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parses the HTML source code.
141 142 143 |
# File 'lib/ronin/web/cli/commands/xml.rb', line 141 def parse(html) Nokogiri::XML(html) end |
#read(source) ⇒ File, String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reads a URI or file.
123 124 125 126 127 128 129 130 |
# File 'lib/ronin/web/cli/commands/xml.rb', line 123 def read(source) if source.start_with?('https://') || source.start_with?('http://') Support::Network::HTTP.get_body(source) else File.new(source) end end |
#run(source, query = @query) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Runs the ronin-web xml
command.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/ronin/web/cli/commands/xml.rb', line 96 def run(source,query=@query) unless query print_error "must specify --xpath or an XPath argument" exit(-1) end doc = parse(read(source)) nodes = if [:first] then doc.at(query) else doc.search(query) end if [:text] puts nodes.inner_text else puts nodes end end |