user14002256
user14002256

Reputation:

Comparing two URLs with and without https

Is there a way I can compare two URLs regardless of their protocol so that https://www.google.com and www.google.com/ are the same URL?

Upvotes: 1

Views: 174

Answers (1)

Maurice Meyer
Maurice Meyer

Reputation: 18106

You could use urlparse:

from urllib.parse import urlparse

u1 = urlparse('https://www.google.com')
u2 = urlparse('http://www.google.com/')
u3 = urlparse('ftp://www.google.com/som/ting/else')

print(u1.netloc == u2.netloc == u3.netloc)

Out:

True

Upvotes: 4

Related Questions