Reputation: 604
I am trying to find if a given string, lets say "Hello" exists in a given page. So far I have the following:
agent = Mechanize.new
page = agent.get('http://www.google.de/')
and what should I do now? I have seen the search method, but it only accepts XPath/CSS expressions. I could try to use xpath to search, but is there a better way?
Upvotes: 4
Views: 4539
Reputation: 2257
You can simply do for general text search:
page.body.include?('Hello')
However when searching a particular html node I recommend using css selectors like that:
page.parser.css('#my_container_element').text.include? 'Hello'
Upvotes: 6