0

I have two URLS from which I have extracted hostnames using urlparse(). The result is: URL1='ads.indiaresults.com' and URL2='haryana.indiaresults.com'

Now how can I check if they are from the same domain or website. I have to make a general method so that it works on all URLS as some time hostnames are like: (www.google.com , www.e-tutes.com)

2
  • With ==? Your URL1 and URL2 are different domains. Commented Feb 1, 2017 at 7:56
  • Use urllib.parse for bringing them into an equal format Commented Feb 1, 2017 at 8:15

1 Answer 1

1

This can be an answer:

Split your URLs :

URL1Split = URL1.split(".")
URL2Split = URL2.split(".")

Then, reverse the lists:

a = URL1Split[::-1]
b = URL2Split[::-1]

Now, you just have to pick the 2 firsts items to get the domain name:

domain1 = a[1] + "." + a[0]
domain2 = b[1] + "." + b[0]

Here's a function if you want :

def compDom(URL1,URL2):
  URL1Split = URL1.split(".")
  URL2Split = URL2.split(".")
  a = URL1Split[::-1]
  b = URL2Split[::-1]
  domain1 = a[1] + "." + a[0]
  domain2 = b[1] + "." + b[0]
  if domain1 == domain2:
      return 1
  else:
      return 0
Sign up to request clarification or add additional context in comments.

1 Comment

Working till now... I will check on more instances... Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.