4

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?

halfelf
  • 9,737
  • 13
  • 54
  • 63
Elchin
  • 584
  • 6
  • 19

1 Answers1

6

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'
Konstantin Rudy
  • 2,237
  • 25
  • 22