Class: Scrapouille::XpathRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/scrapouille/xpath_runner.rb

Instance Method Summary collapse

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

#getObject



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