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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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:
Seen in action:
The more convoluted answer here previously used
URI.parse(root).merge(URI.parse(href)).to_s.Thanks to @pguardiario for the improvement.