Checking for a Few Attributes
Q: Can I perform a single search and get all of the elements with “href” or “action” attributes? Something like this:doc.search("[@href]|[@action]")
Similarly, is it possible to get all elements with both attributes present?
A: In recent Hpricots (after 2006 Mar 17,) you can go ahead and use the search from the question:
In earlier Hpricots, you’ll need to do two searches:ele = doc.search("[@href]") ele.push *doc.search("[@type]")
As for doing a search which finds elements with both attributes, you can go ahead and stack the search in newer Hpricots:doc.search("[@href][@type]")