How can I get the absolute URL when extracting links using Nokogiri?
问题 I'm using Nokogiri to extract links from a page but I would like to get the absolute path even though the one on the page is a relative one. How can I accomplish this? 回答1: Nokogiri is unrelated, other than the fact that it gives you the link anchor to begin with. Use Ruby's URI library to manage paths: absolute_uri = URI.join( page_url, href ).to_s Seen in action: require 'uri' # The URL of the page with the links page_url = 'http://foo.com/zee/zaw/zoom.html' # A variety of links to test.