Skip to content

Instantly share code, notes, and snippets.

@milafrerichs
Created January 18, 2014 15:15
Show Gist options
  • Save milafrerichs/8491837 to your computer and use it in GitHub Desktop.
Save milafrerichs/8491837 to your computer and use it in GitHub Desktop.
A little nokogiri helper I wrote to search and get text or attributes from HTML documents
class NokogiriSearcher
def initialize(html)
@doc = Nokogiri::HTML(html)
end
def search(searchText)
@doc.search(searchText)
end
def first_text_from_search(searchText)
search(searchText).first.text().strip()
end
def first_attr_from_search(searchText,attr)
search(searchText).first[attr]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment