Question

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?

Was it helpful?

Solution

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'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top