Class: Arachni::Page
Overview
It holds page data like elements, cookies, headers, etc…
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
The HTML response.
-
#code ⇒ Fixnum
readonly
The HTTP response code.
-
#cookiejar ⇒ Array<Element::Cookie>
Cookies extracted from the supplied cookiejar.
- #cookies ⇒ Array<Element::Cookie>
- #forms ⇒ Array<Element::Form>
-
#headers ⇒ Array<Element::Header>
readonly
Request headers.
- #links ⇒ Array<Element::Link>
-
#method ⇒ String
readonly
The request method that returned the page.
- #paths ⇒ Array<String> readonly
-
#query_vars ⇒ Hash
readonly
Url variables.
- #request_headers ⇒ Hash readonly
- #response_headers ⇒ Hash readonly
-
#url ⇒ String
readonly
Url of the page.
Class Method Summary collapse
- .from_response(res, opts = Options) ⇒ Object (also: from_http_response)
- .from_url(url, opts = {}, &block) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #document ⇒ Object
- #dup ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #html ⇒ Object
-
#initialize(opts = {}) ⇒ Page
constructor
A new instance of Page.
- #text? ⇒ Boolean
- #title ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Page
Returns a new instance of Page.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/arachni/page.rb', line 123 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 the HTML response.
50 51 52 |
# File 'lib/arachni/page.rb', line 50 def body @body end |
#code ⇒ Fixnum (readonly)
Returns the HTTP response code.
35 36 37 |
# File 'lib/arachni/page.rb', line 35 def code @code end |
#cookiejar ⇒ Array<Element::Cookie>
Cookies extracted from the supplied cookiejar
98 99 100 |
# File 'lib/arachni/page.rb', line 98 def @cookiejar end |
#headers ⇒ Array<Element::Header> (readonly)
Request headers
57 58 59 |
# File 'lib/arachni/page.rb', line 57 def headers @headers end |
#method ⇒ String (readonly)
Returns the request method that returned the page.
40 41 42 |
# File 'lib/arachni/page.rb', line 40 def method @method end |
#paths ⇒ Array<String> (readonly)
70 71 72 |
# File 'lib/arachni/page.rb', line 70 def paths @paths end |
#query_vars ⇒ Hash (readonly)
Returns url variables.
45 46 47 |
# File 'lib/arachni/page.rb', line 45 def query_vars @query_vars end |
#request_headers ⇒ Hash (readonly)
62 63 64 |
# File 'lib/arachni/page.rb', line 62 def request_headers @request_headers end |
#response_headers ⇒ Hash (readonly)
67 68 69 |
# File 'lib/arachni/page.rb', line 67 def response_headers @response_headers end |
#url ⇒ String (readonly)
Returns url of the page.
30 31 32 |
# File 'lib/arachni/page.rb', line 30 def url @url end |
Class Method Details
.from_response(res, opts = Options) ⇒ Object Also known as: from_http_response
118 119 120 |
# File 'lib/arachni/page.rb', line 118 def self.from_response( res, opts = Options ) Parser.new( res, opts ).page end |
.from_url(url, opts = {}, &block) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/arachni/page.rb', line 100 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
173 174 175 |
# File 'lib/arachni/page.rb', line 173 def ==( other ) hash == other.hash end |
#document ⇒ Object
146 147 148 |
# File 'lib/arachni/page.rb', line 146 def document @document ||= Nokogiri::HTML( @body ) end |
#dup ⇒ Object
181 182 183 |
# File 'lib/arachni/page.rb', line 181 def dup self.deep_clone end |
#eql?(other) ⇒ Boolean
177 178 179 |
# File 'lib/arachni/page.rb', line 177 def eql?( other ) self == other end |
#hash ⇒ Object
167 168 169 170 171 |
# File 'lib/arachni/page.rb', line 167 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 |
#html ⇒ Object
142 143 144 |
# File 'lib/arachni/page.rb', line 142 def html @body end |
#text? ⇒ Boolean
150 151 152 |
# File 'lib/arachni/page.rb', line 150 def text? !!@text end |
#title ⇒ Object
154 155 156 |
# File 'lib/arachni/page.rb', line 154 def title document.css( 'title' ).first.text rescue nil end |
#to_hash ⇒ Object
158 159 160 161 162 163 164 165 |
# File 'lib/arachni/page.rb', line 158 def to_hash instance_variables.reduce({}) do |h, iv| if iv != :@document h[iv.to_s.gsub( '@', '').to_sym] = try_dup( instance_variable_get( iv ) ) end h end end |