문제

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?

도움이 되었습니까?

해결책

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'
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top