Class: Ronin::Web::CLI::Commands::Screenshot Private
- Inherits:
-
Ronin::Web::CLI::Command
- Object
- Core::CLI::Command
- Ronin::Web::CLI::Command
- Ronin::Web::CLI::Commands::Screenshot
- Includes:
- Core::CLI::Logging, BrowserOptions
- Defined in:
- lib/ronin/web/cli/commands/screenshot.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.
Screenshots one or more URLs.
Usage
ronin-web screenshot [options] {URL [...] | --file FILE}
Options
-B, --browser NAME|PATH The browser name or path to execute
-W, --width WIDTH Sets the width of the browser viewport (Default: 1024)
-H, --height HEIGHT Sets the height of the browser viewport (Default: 768)
-f, --file FILE Input file to read URLs from
-F, --format png|jpg Screenshot image format (Default: png)
-d, --directory DIR Directory to save images to (Default: /data/home/postmodern/code/ronin-rb/ronin-web)
--full Screenshots the full page
-C, --css-path CSSPath The CSSpath selector to screenshot
-h, --help Print help information
Arguments
URL ... The URL visit and screenshot
Instance Method Summary collapse
-
#image_path_for(url) ⇒ String
private
Generates the image path for a given URL.
-
#parse_url(url) ⇒ URI::HTTP, URI::HTTPS
private
Parses a URL.
-
#process_url(url) ⇒ Object
private
Visits and screenshots a URL.
-
#run(*urls) ⇒ Object
private
Runs the
ronin-web screenshot
command.
Methods included from BrowserOptions
#browser, #browser_kwargs, included
Instance Method Details
#image_path_for(url) ⇒ 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.
Generates the image path for a given URL.
172 173 174 175 176 177 178 179 180 |
# File 'lib/ronin/web/cli/commands/screenshot.rb', line 172 def image_path_for(url) uri = parse_url(url) path = File.join([:directory],uri.host,uri.request_uri) path << 'index' if path.end_with?('/') path << ".#{[:format]}" return path end |
#parse_url(url) ⇒ URI::HTTP, URI::HTTPS
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 a URL.
156 157 158 159 160 161 |
# File 'lib/ronin/web/cli/commands/screenshot.rb', line 156 def parse_url(url) URI.parse(url) rescue URI::InvalidURI print_error "invalid URI: #{url}" exit(1) end |
#process_url(url) ⇒ 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.
Visits and screenshots a URL.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/ronin/web/cli/commands/screenshot.rb', line 128 def process_url(url) begin browser.goto(url) rescue Ferrum::StatusError print_error "failed to request URL: #{url}" end image_path = image_path_for(url) FileUtils.mkdir_p(File.dirname(image_path)) log_info "Screenshotting #{url} to #{image_path} ..." browser.screenshot( path: image_path, format: [:format], full: [:full], selector: [:css_path] ) end |
#run(*urls) ⇒ 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 screenshot
command.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/ronin/web/cli/commands/screenshot.rb', line 105 def run(*urls) if [:file] File.open([:file]) do |file| file.each_line(chomp: true) do |url| process_url(url) end end elsif !urls.empty? urls.each do |url| process_url(url) end else print_error "must specify --file or URL arguments" exit(-1) end end |