Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Newbie Metchanize Question

Reply
Thread Tools

Newbie Metchanize Question

 
 
Becca Girl
Guest
Posts: n/a
 
      10-30-2008
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/.

 
Reply With Quote
 
 
 
 
Becca Girl
Guest
Posts: n/a
 
      10-30-2008
Sorry for the misspelling of the subject in the previous post!
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Becca Girl
Guest
Posts: n/a
 
      10-31-2008
Figured it out.

page.search("div.details").search("a[@href*='unique_id']")
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Becca Girl
Guest
Posts: n/a
 
      10-31-2008
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/.

 
Reply With Quote
 
Aaron Patterson
Guest
Posts: n/a
 
      10-31-2008
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/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VONAGE Newbie w/newbie question New_kid@nowhere.new VOIP 0 08-11-2007 01:40 PM
another newbie question from another newbie.... Lee UK VOIP 4 05-17-2005 04:10 PM
newbie: cisco vlan newbie question No Spam Cisco 3 06-07-2004 10:02 AM
dumb newbie question (or newbie dumb question) Jerry C. Perl Misc 8 11-23-2003 04:11 AM
Newbie! I'm a newbie! What's wrong with this program? Id0x Python 4 07-20-2003 11:40 PM



Advertisments