Created
January 18, 2014 15:15
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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