Part II The value you pass in: href should be an exact match by default. So the href in your example will only match <a href="/something"></a>
, not <a href="foo.com/something/a"></a>
What you want to do is pass in the regular expression so that it matches the substring in the href field. For instance:
page = agent.get('http://foo.com/').links_with(:href => %r{/something/})
edit Part I To make it select links only by reference, add the nokogiri style lookup method to your line. Like this:
page = agent.get('http://foo.com/').search("div#content").links_with(:href => %r{/something/})
Well, that doesn't work, because after doing page = agent.get('http://foo.com/').search("div#content")
you get a Nokogiri object instead of mechanizing, so links_with will not work. However, you can extract links from a Nokogiri object using the css method. I would suggest something like:
page = agent.get('http://foo.com/').search("div#content").css("a")
If this does not work, I suggest checking out http://nokogiri.org/tutorials
source share