久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

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

Python從URL中提取域名

瀏覽:176日期: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 內(nèi)置的模塊 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 編程
相關文章:
主站蜘蛛池模板: 新沂市| 沙洋县| 泾川县| 错那县| 乡宁县| 资兴市| 成武县| 许昌县| 商城县| 化隆| 崇文区| 普安县| 安福县| 仪征市| 无极县| 剑河县| 微山县| 柳林县| 方城县| 晋宁县| 沈阳市| 贞丰县| 黄平县| 韩城市| 措美县| 沙雅县| 通州市| 龙游县| 天门市| 枣阳市| 崇仁县| 长兴县| 新干县| 阜城县| 呼和浩特市| 新闻| 阿克| 衡阳市| 青铜峡市| 江华| 红河县|