Yout don't. Relative url's are perfectly acceptable per the RFCs. They are to be interpreted by the User Agent (that's you) as relative to the current url (that being the URL you retrieved whose content returned the relative URLs.)
You need to make them relative to that URL, so a relative URL like foobar.html
on a page whose full URL is http://somedomain/alpha/bravo/charlie/index.html
gets converted to http://somedomain/alpha/bravo/charlie/foobar.html
.