Module: Spidr::Body
- Included in:
- Page
- Defined in:
- lib/spidr/body.rb
Instance Method Summary collapse
-
#at(*arguments) ⇒ Nokogiri::HTML::Node, ...
(also: #%)
Searches for the first occurrence an XPath or CSS Path expression.
-
#body ⇒ String
(also: #to_s)
The body of the response.
-
#doc ⇒ Nokogiri::HTML::Document, ...
Returns a parsed document object for HTML, XML, RSS and Atom pages.
-
#search(*paths) ⇒ Array
(also: #/)
Searches the document for XPath or CSS Path paths.
-
#title ⇒ String
The title of the HTML page.
Instance Method Details
#at(*arguments) ⇒ Nokogiri::HTML::Node, ... Also known as: %
Searches for the first occurrence an XPath or CSS Path expression.
75 76 77 78 79 |
# File 'lib/spidr/body.rb', line 75 def at(*arguments) if doc doc.at(*arguments) end end |
#body ⇒ String Also known as: to_s
The body of the response.
11 12 13 |
# File 'lib/spidr/body.rb', line 11 def body (response.body || '') end |
#doc ⇒ Nokogiri::HTML::Document, ...
Returns a parsed document object for HTML, XML, RSS and Atom pages.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/spidr/body.rb', line 26 def doc unless body.empty? begin if html? @doc ||= Nokogiri::HTML(body) elsif (rss? || atom? || xml? || xsl?) @doc ||= Nokogiri::XML(body) end rescue end end end |
#search(*paths) ⇒ Array Also known as: /
Searches the document for XPath or CSS Path paths.
55 56 57 58 59 60 61 |
# File 'lib/spidr/body.rb', line 55 def search(*paths) if doc doc.search(*paths) else [] end end |
#title ⇒ String
The title of the HTML page.
90 91 92 93 94 |
# File 'lib/spidr/body.rb', line 90 def title if (node = at('//title')) node.inner_text end end |