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-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
how to get an absolute address of a link
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password