how to get an absolute address of a link

T

Tsunami Script

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 .
 
L

Luis Parravicini

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://example.com', '/path/a/b')
=> #<URI::HTTP:0xb7ce2b08 URL:http://example.com/path/a/b>
irb(main):002:0> URI.join('http://example.com', 'http://google.com/path/a/b')
=> #<URI::HTTP:0xb7cdf28c URL:http://google.com/path/a/b>
irb(main):003:0>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,187
Members
46,729
Latest member
ScarlettJe

Latest Threads

Top