Class: Scrapouille::XpathRunner
- Inherits:
-
Object
- Object
- Scrapouille::XpathRunner
- Defined in:
- lib/scrapouille/xpath_runner.rb
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(xpath, html) ⇒ XpathRunner
constructor
A new instance of XpathRunner.
Constructor Details
#initialize(xpath, html) ⇒ XpathRunner
Returns a new instance of XpathRunner.
6 7 8 9 |
# File 'lib/scrapouille/xpath_runner.rb', line 6 def initialize(xpath, html) @xpath = xpath @html_content = Nokogiri::HTML(html) end |
Instance Method Details
#get ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/scrapouille/xpath_runner.rb', line 14 def get result = html_content.xpath(xpath) if peek = result.first if Nokogiri::XML::Attr === peek result.map(&:value) else result.map(&:text) end else [] end end |