[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

how to get an absolute address of a link

Tsunami Script

1/28/2009 11:30:00 AM

Is there some URL lib that I can use to get the absolute address of a
relative URL ? Maybe I could pass a "base" link to the method . Ideally
, I would like to know if this could by achieved from mechanize , but
anything would do .
I wrote my own a while back , and I'm using it , but I would like to
know if something already exists .
--
Posted via http://www.ruby-....

2 Answers

Luis Parravicini

1/28/2009 4:25:00 PM

0

On Wed, Jan 28, 2009 at 9:30 AM, Tsunami Script <lyon2003@lycos.com> wrote:
> Is there some URL lib that I can use to get the absolute address of a
> relative URL ? Maybe I could pass a "base" link to the method . Ideally
> , I would like to know if this could by achieved from mechanize , but
> anything would do .

You can use URI.join

irb -ruri
irb(main):001:0> URI.join('http://exampl..., '/path/a/b')
=> #<URI::HTTP:0xb7ce2b08 URL:http://example.com/pa...
irb(main):002:0> URI.join('http://exampl..., 'http://google.com/pat...)
=> #<URI::HTTP:0xb7cdf28c URL:http://google.com/pa...
irb(main):003:0>



--
Luis Parravicini
http://ktulu.co...

Tsunami Script

1/28/2009 4:33:00 PM

0

Very nice ! Thanks ! I was wondering if it would handle joins with
arguments like

arg1 = "http://site...
arg2 = "index.html"

or arg1 = "http://site....
arg2 = "/index.html"

and it seems to work great . Thank you !
--
Posted via http://www.ruby-....