What is the preferred solution for checking if an URL is relative or absolute?
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.
Python 2
You can use the
urlparsemodule to parse an URL and then you can check if it’s relative or absolute by checking whether it has the host name set.Python 3
urlparsehas been moved tourllib.parse, so use the following: