In addition to @Artefacto's answer, and if you are outputting the scraped HTML somewhere, you could simply add to the head of the document, which will establish the base URL for all relative URLs in the document as the specified href. Have a look at http://www.w3schools.com/tags/tag_base.asp