# Newbie Metchanize Question

**URL:** <https://www.ruby-forum.com/t/newbie-metchanize-question/152190>\
**Category:** Ruby\
**Created:** [October 31, 2008, 12:58am UTC](https://www.ruby-forum.com/t/newbie-metchanize-question/152190 "2008-10-31T00:58:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [October 31, 2008, 12:58am UTC](https://www.ruby-forum.com/t/newbie-metchanize-question/152190/1 "2008-10-31T00:58:03Z")

</div>

Hello.

I have a page that I get in mechanize.

I can view all of the links on the page, but I actually only want to get  
some of the links on the page.

How can I grab only what I need?

The source code looks like this:

link

I want to get the url for each of the details classes or get only the  
url’s that contain “unique\_link” in the them.

Right now I’m using this code to get all of the results.

search\_results.links.each.do |link|  
puts link.text  
end

THANKS!

---

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [October 31, 2008, 12:59am UTC](https://www.ruby-forum.com/t/newbie-metchanize-question/152190/2 "2008-10-31T00:59:10Z")

</div>

Sorry for the misspelling of the subject in the previous post!

---

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [October 31, 2008, 1:16am UTC](https://www.ruby-forum.com/t/newbie-metchanize-question/152190/3 "2008-10-31T01:16:23Z")

</div>

Figured it out.

page.search(“div.details”).search(“a[@href\*=‘unique\_id’]”)

---

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [October 31, 2008, 1:38am UTC](https://www.ruby-forum.com/t/newbie-metchanize-question/152190/4 "2008-10-31T01:38:55Z")

</div>

Becca G. wrote:

> Figured it out.
> 
> page.search(“div.details”).search(“a[@href\*=‘unique\_id’]”)

After re-reading the documentation, I see that I should be able to  
simply do something like this --\> page.links.href(’/unique\_id’) but I  
get nothing. No results, nada. Am I doing this wrong?

The previous code works, but I think that I should do this more  
efficiently.

---

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [October 31, 2008, 2:31am UTC](https://www.ruby-forum.com/t/newbie-metchanize-question/152190/5 "2008-10-31T02:31:23Z")

</div>

On Fri, Oct 31, 2008 at 09:38:00AM +0900, Becca G. wrote:

> Becca G. wrote:
> 
> > Figured it out.
> > 
> > page.search(“div.details”).search(“a[@href\*=‘unique\_id’]”)
> 
> After re-reading the documentation, I see that I should be able to  
> simply do something like this --\> page.links.href(’/unique\_id’) but I  
> get nothing. No results, nada. Am I doing this wrong?

You can do:

page.links\_with(:href =\> /unique\_id/)

Which will search links that have href’s which match /unique\_id/

Hope that helps.
