O'Reilly logo

Text Processing with Ruby by Rob Miller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with Elements

Once we’ve selected the elements that are appropriate for the task at hand, using either XPath or CSS selectors, our job is most likely only half done. We typically want to actually do something with the elements we’ve matched.

There are two types of things we might want to do with the elements. The first set of tasks involves extracting information—either the text of elements within the set or the contents of attributes on those elements. Exactly where the information is stored depends both on the elements we’re dealing with and what we’re trying to do. If we’ve matched an image, the interesting part might be the src attribute, specifying the URL of the image; if we’ve matched a paragraph, then we’re likely to be interested ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required