Newbie Metchanize Question

Discussion in 'Ruby' started by Becca Girl, Oct 30, 2008.

  1. Becca Girl

    Becca Girl Guest

    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:

    <div class="details">
    <a href="website/unique_link/id">link</a>
    </div>


    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!
    --
    Posted via http://www.ruby-forum.com/.
    Becca Girl, Oct 30, 2008
    #1
    1. Advertising

  2. Becca Girl

    Becca Girl Guest

    Re: Newbie Mechanize Question

    Sorry for the misspelling of the subject in the previous post!
    --
    Posted via http://www.ruby-forum.com/.
    Becca Girl, Oct 30, 2008
    #2
    1. Advertising

  3. Becca Girl

    Becca Girl Guest

    Re: Newbie Mechanize Question

    Figured it out.

    page.search("div.details").search("a[@href*='unique_id']")
    --
    Posted via http://www.ruby-forum.com/.
    Becca Girl, Oct 31, 2008
    #3
  4. Becca Girl

    Becca Girl Guest

    Re: Newbie Mechanize Question

    Becca Girl 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.




    --
    Posted via http://www.ruby-forum.com/.
    Becca Girl, Oct 31, 2008
    #4
  5. Re: Newbie Mechanize Question

    On Fri, Oct 31, 2008 at 09:38:00AM +0900, Becca Girl wrote:
    > Becca Girl 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.

    --
    Aaron Patterson
    http://tenderlovemaking.com/
    Aaron Patterson, Oct 31, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jerry C.
    Replies:
    8
    Views:
    205
    Uri Guttman
    Nov 23, 2003
  2. Kruno Saho
    Replies:
    0
    Views:
    125
    Kruno Saho
    Apr 7, 2013
  3. Dave Angel
    Replies:
    0
    Views:
    109
    Dave Angel
    Apr 7, 2013
  4. rusi
    Replies:
    0
    Views:
    99
  5. Miki Tebeka
    Replies:
    0
    Views:
    74
    Miki Tebeka
    Apr 7, 2013
Loading...

Share This Page