Nokogiri can do this (now) using jQuery extensions to CSS:
require 'nokogiri'
html="
<html>
<body>
<p>foo</p>
<p>bar</p>
</body>
</html>
"
doc = Nokogiri::HTML(html)
doc.at('p:contains("bar")').text.strip
=> "bar"
More Related Contents:
- Why does installing Nokogiri on Mac OS fail with libiconv is missing?
- Nokogiri/Xpath namespace query
- Mac user and getting WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.7.3
- Installing Nokogiri on OSX 10.10 Yosemite
- Nokogiri, open-uri, and Unicode Characters
- Error to install Nokogiri on OSX 10.9 Maverick?
- Print an XML document without the XML header line at the top
- How can I get the absolute URL when extracting links using Nokogiri?
- extract single string from HTML using Ruby/Mechanize (and Nokogiri)
- XPath axis, get all following nodes until
- Why does Ruby 1.9.2 remove “.” from LOAD_PATH, and what’s the alternative?
- How to count duplicate elements in a Ruby array
- What is the difference between Raising Exceptions vs Throwing Exceptions in Ruby?
- List of installed gems?
- How can I find the number of days between two Date objects in Ruby?
- Why is sum so much faster than inject(:+)?
- Ruby: extend self
- What are those pipe symbols for in Ruby?
- How to install ruby-debug when needing necessary libraries and/or headers
- How do methods use hash arguments in Ruby?
- How to cleanly initialize attributes in Ruby with new?
- Dynamically set local variables in Ruby [duplicate]
- Mac Rmagick won’t install with Xcode 4.2
- selenium 2.4.0, how to check for presence of an alert
- The Class/Object Paradox confusion
- Round up to the nearest tenth?
- How to use double brackets in a regular expression?
- Is there a ‘variable_get’ method? If not, how can I create my own?
- unzip (zip, tar, tag.gz) files with ruby
- What are the magic $-prefixed variables in Ruby? [closed]