我在資料庫中有兩種型別的地址:
url_1 = "http://country.city.street/"
url_2 = "http://country.city.street:8180/"
我需要url_pattern = "country.city.street"在 DNS 服務器中使用統一的地址格式 ( )。我http://從一開始就洗掉了該部分,但在地址末尾無法獲得良好的結果。有誰知道我可以用什么來獲得url_pattern標準?
url_1 = "http://country.city.street/"
url_2 = "http://country.city.street:8180/"
url_1 = url_1[7:]
url_2 = url_2[7:]
uj5u.com熱心網友回復:
有用于 URL 決議的標準模塊
from urllib.parse import urlparse
print(urlparse("http://country.city.street:8180/").hostname)
uj5u.com熱心網友回復:
您可以使用urllib.parse模塊。它有一個urlparse函式,您可以使用它來將 URL 決議為組件。
>>> import urllib.parse
>>> urllib.parse.urlparse("http://country.city.street/")
ParseResult(scheme='http', netloc='country.city.street', path='/', params='', query='', fragment='')
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/354300.html
上一篇:空白字串的正則運算式
下一篇:如何匹配網址但不包含點
