Class: Arachni::Page
Overview
It holds page data like elements, cookies, headers, etc…
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
HTTP response body.
-
#code ⇒ Fixnum
readonly
HTTP response code.
-
#cookiejar ⇒ Array<Element::Cookie>
Cookies extracted from the supplied cookie-jar.
- #cookies ⇒ Array<Element::Cookie>
- #forms ⇒ Array<Element::Form>
-
#headers ⇒ Array<Element::Header>
readonly
HTTP request headers.
- #links ⇒ Array<Element::Link>
-
#paths ⇒ Array<String>
readonly
Paths contained in this page.
-
#query_vars ⇒ Hash
readonly
URL query parameters.
-
#request_headers ⇒ Hash
readonly
HTTP request headers.
-
#response_headers ⇒ Hash
readonly
HTTP response headers.
-
#url ⇒ String
readonly
URL of the page.
Class Method Summary collapse
- .from_response(res, opts = Options) ⇒ Page (also: from_http_response)
- .from_url(url, opts = {}, &block) ⇒ Page
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#document ⇒ Nokogiri::HTML
Parsed HTML document.
- #dup ⇒ Object
-
#elements ⇒ Array
All page elements.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #html ⇒ Object
-
#initialize(opts = {}) ⇒ Page
constructor
A new instance of Page.
- #marshal_dump ⇒ Object
- #marshal_load(h) ⇒ Object
-
#method(*args) ⇒ String
The request method that returned the page.
-
#platforms ⇒ Platform
Applicable platforms for the page.
-
#text? ⇒ Boolean
‘true` if the body of the page is text-base, `false` otherwise.
-
#title ⇒ String
Title of the page.
-
#to_h ⇒ Hash
(also: #to_hash)
Converts the page data to a hash.
Constructor Details
#initialize(opts = {}) ⇒ Page
Returns a new instance of Page.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/arachni/page.rb', line 103 def initialize( opts = {} ) opts.each { |k, v| instance_variable_set( "@#{k}".to_sym, try_dup( v ) ) } @forms ||= [] @links ||= [] @cookies ||= [] @headers ||= [] @cookiejar ||= {} @paths ||= [] @response_headers ||= {} @request_headers ||= {} @query_vars ||= {} @url = Utilities.normalize_url( @url ) @body ||= '' end |
Instance Attribute Details
#body ⇒ String (readonly)
Returns HTTP response body.
36 37 38 |
# File 'lib/arachni/page.rb', line 36 def body @body end |
#code ⇒ Fixnum (readonly)
Returns HTTP response code.
30 31 32 |
# File 'lib/arachni/page.rb', line 30 def code @code end |
#cookiejar ⇒ Array<Element::Cookie>
Returns Cookies extracted from the supplied cookie-jar.
64 65 66 |
# File 'lib/arachni/page.rb', line 64 def @cookiejar end |
#headers ⇒ Array<Element::Header> (readonly)
Returns HTTP request headers.
39 40 41 |
# File 'lib/arachni/page.rb', line 39 def headers @headers end |
#paths ⇒ Array<String> (readonly)
Returns Paths contained in this page.
48 49 50 |
# File 'lib/arachni/page.rb', line 48 def paths @paths end |
#query_vars ⇒ Hash (readonly)
Returns URL query parameters.
33 34 35 |
# File 'lib/arachni/page.rb', line 33 def query_vars @query_vars end |
#request_headers ⇒ Hash (readonly)
Returns HTTP request headers.
42 43 44 |
# File 'lib/arachni/page.rb', line 42 def request_headers @request_headers end |
#response_headers ⇒ Hash (readonly)
Returns HTTP response headers.
45 46 47 |
# File 'lib/arachni/page.rb', line 45 def response_headers @response_headers end |
#url ⇒ String (readonly)
Returns URL of the page.
27 28 29 |
# File 'lib/arachni/page.rb', line 27 def url @url end |
Class Method Details
.from_response(res, opts = Options) ⇒ Page Also known as: from_http_response
97 98 99 |
# File 'lib/arachni/page.rb', line 97 def self.from_response( res, opts = Options ) Parser.new( res, opts ).page end |
.from_url(url, opts = {}, &block) ⇒ Page
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/arachni/page.rb', line 77 def self.from_url( url, opts = {}, &block ) responses = [] opts[:precision] ||= 1 opts[:precision].times { HTTP.get( url, opts[:http] || {} ) do |res| responses << res next if responses.size != opts[:precision] block.call( from_response( responses ) ) if block_given? end } if !block_given? HTTP.run from_response( responses ) end end |
Instance Method Details
#==(other) ⇒ Object
187 188 189 |
# File 'lib/arachni/page.rb', line 187 def ==( other ) hash == other.hash end |
#document ⇒ Nokogiri::HTML
Returns Parsed HTML document.
144 145 146 |
# File 'lib/arachni/page.rb', line 144 def document @document ||= Nokogiri::HTML( @body ) end |
#dup ⇒ Object
195 196 197 |
# File 'lib/arachni/page.rb', line 195 def dup self.deep_clone end |
#elements ⇒ Array
Returns All page elements.
128 129 130 |
# File 'lib/arachni/page.rb', line 128 def elements @links | @forms | @cookies | @headers end |
#eql?(other) ⇒ Boolean
191 192 193 |
# File 'lib/arachni/page.rb', line 191 def eql?( other ) self == other end |
#hash ⇒ Object
181 182 183 184 185 |
# File 'lib/arachni/page.rb', line 181 def hash ((links.map { |e| e.hash } + forms.map { |e| e.hash } + .map { |e| e.hash } + headers.map { |e| e.hash }).sort.join + body.to_s).hash end |
#marshal_dump ⇒ Object
148 149 150 151 152 153 154 |
# File 'lib/arachni/page.rb', line 148 def marshal_dump instance_variables.inject( {} ) do |h, iv| next h if iv == :@document h[iv] = instance_variable_get( iv ) h end end |
#marshal_load(h) ⇒ Object
156 157 158 |
# File 'lib/arachni/page.rb', line 156 def marshal_load( h ) h.each { |k, v| instance_variable_set( k, v ) } end |
#method(*args) ⇒ String
Returns the request method that returned the page.
133 134 135 136 |
# File 'lib/arachni/page.rb', line 133 def method( *args ) return super( *args ) if args.any? @method end |
#platforms ⇒ Platform
Returns Applicable platforms for the page.
123 124 125 |
# File 'lib/arachni/page.rb', line 123 def platforms Platform::Manager[@url] end |
#text? ⇒ Boolean
Returns ‘true` if the body of the page is text-base, `false` otherwise.
162 163 164 |
# File 'lib/arachni/page.rb', line 162 def text? !!@text end |
#title ⇒ String
Returns Title of the page.
167 168 169 |
# File 'lib/arachni/page.rb', line 167 def title document.css( 'title' ).first.text rescue nil end |
#to_h ⇒ Hash Also known as: to_hash
Returns Converts the page data to a hash.
172 173 174 175 176 177 178 |
# File 'lib/arachni/page.rb', line 172 def to_h instance_variables.reduce({}) do |h, iv| next h if iv == :@document h[iv.to_s.gsub( '@', '').to_sym] = try_dup( instance_variable_get( iv ) ) h end end |