+5  A: 

You can do it like this:

doc = Nokogiri::HTML.parse(<<-HTML_END)
<div class="heat">
   <a href='http://example.org/site/1/'&gt;site 1</a>
   <a href='http://example.org/site/2/'&gt;site 2</a>
   <a href='http://example.org/site/3/'&gt;site 3</a>
</div>
<div class="wave">
   <a href='http://example.org/site/4/'&gt;site 4</a>
   <a href='http://example.org/site/5/'&gt;site 5</a>
   <a href='http://example.org/site/6/'&gt;site 6</a>
</div>
HTML_END

l = doc.css('div.heat a').map { |link| link['href'] }

This solution finds all anchor elements using a css selector and collects their href attributes.

sris
very nice, you saved my day thanks :)one thing I get now all links from the site, but I only want the links inside the div with clas "heat". is this also possible?
gustavgans
yes, i've updated the example.
sris
would this example also work for any link that was in a <p> and not a live link?
Aaron Moodie
A: 

ok this code works perfect for me, thanks to sris

p doc.xpath('//div[@class="heat"]/a').map { |link| link['href'] }
gustavgans