国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

Python從URL中提取域名

瀏覽:177日期:2022-06-27 16:30:20

問題描述

Python如何從URL中提取域名?url有各種格式的如下:

輸入:

https://docs.google.com/spreadsheet/ccc?key=blah-blah-blah-blah#gid=1https://stackoverflow.com/questions/1234567/blah-blah-blah-blahhttp://www.domain.comhttps://www.other-domain.com/whatever/blah/blah/?v1=0&v2=blah+blah ...

輸出:

docs.google.comstackoverflow.comwww.domain.comwww.other-domain.com

問題解答

回答1:

使用Python 內置的模塊 urlparse

from urlparse import *url = ’https://docs.google.com/spreadsheet/ccc?key=blah-blah-blah-blah#gid=1’result = urlparse(url)

result 包含了URL的所有信息

回答2:

原文出處:Python實用腳本清單

從URL中提取域名

def extractDomainFromURL(url): '''Get domain name from url''' from urlparse import urlparse parsed_uri = urlparse(url) domain = ’{uri.netloc}’.format(uri=parsed_uri) return domain

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 荣成市| 柳州市| 武清区| 湘阴县| 祁门县| 镇康县| 法库县| 金秀| 雷山县| 宁强县| 慈溪市| 武穴市| 朝阳区| 永仁县| 扎囊县| 新和县| 泉州市| 乌鲁木齐市| 丰宁| 斗六市| 城固县| 温州市| 青浦区| 长丰县| 金华市| 辽阳市| 酉阳| 临猗县| 甘泉县| 南溪县| 米脂县| 镇平县| 康保县| 三明市| 大新县| 山丹县| 呈贡县| 镇雄县| 茌平县| 安溪县| 丹巴县|