Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Parse part of url- python

I have two types of addresses in DataBase:

url_1  = "http://country.city.street/"
url_2  = "http://country.city.street:8180/"

I need to get a uniform address format (url_pattern = "country.city.street") to use in a DNS server. I removed the http:// part from the beginning but can’t get a good result with the end of the address. Does anyone have an idea what I could use to get a url_pattern standard?

url_1  = "http://country.city.street/"
url_2  = "http://country.city.street:8180/"

url_1 = url_1[7:]
url_2 = url_2[7:]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There is standard module for URL parsing

from urllib.parse import urlparse
print(urlparse("http://country.city.street:8180/").hostname)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading