安装

PyPI的最新稳定版本:

 pip install tld

或者GitHub的最新稳定版本:

 pip install https://github.com/barseghyanartur/tld/archive/stable.tar.gz

或BitBucket的最新稳定版本:

 点击安装https://bitbucket.org/barseghyanartur/tld/get/stable.tar.gz

用法示例

从给定的URL 获取TLD名称作为字符串

 from tld import get_tld

 get_tld("http://www.google.co.uk")
# 'co.uk' get_tld("http://www.google.idontexist", fail_silently=True)
# None

获取TLD作为对象

 from tld import get_tld

 res = get_tld("http://some.subdomain.google.co.uk", as_object=True)

 res
# 'co.uk' res.subdomain
# 'some.subdomain' res.domain
# 'google' res.tld
# 'co.uk' res.fld
# 'google.co.uk' res.parsed_url
# SplitResult(
# scheme='http',
# netloc='some.subdomain.google.co.uk',
# path='',
# query='',
# fragment=''
# )

获取TLD名称,忽略丢失的协议

 from tld import get_tld, get_fld

 get_tld("www.google.co.uk", fix_protocol=True)
# 'co.uk' get_fld("www.google.co.uk", fix_protocol=True)
# 'google.co.uk'

将TLD部件作为元组返回

 from tld import parse_tld

 parse_tld('http://www.google.com')
# 'com', 'google', 'www'

从给定的URL 获取第一级域名作为字符串

 from tld import get_fld

 get_fld("http://www.google.co.uk")
# 'google.co.uk' get_fld("http://www.google.idontexist", fail_silently=True)
# None

good good study ,day day up !!!

python 从给定的URL中提取顶级域名(TLD)的更多相关文章

  1. Java获取URL中的顶级域名domain的工具类

    方式一: import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; import jav ...

  2. 飘逸的python - 用urlparse从url中抽离出想要的信息

    最近有个需求,要检测配置中的那些url的域名是否都正常,即是否都能ping通. 不过配置中url格式是这样的 http://www.something.com:1234/ . 要ping的是www.s ...

  3. python 从url中提取域名和path

    使用Python 内置的模块 urlparse from urlparse import * url = 'https://docs.google.com/spreadsheet/ccc?key=bl ...

  4. 从url中提取参数名和参数值(转)

    在已知参数名的情况下,获取参数值,使用正则表达式能很容易做到.js的实现方法如下: function getValue(url, name) { var reg = new RegExp('(\\?| ...

  5. 从一个标准URL中提取文件的扩展名

    例如:http://www.sina.cn/abc/de.php?id=1  提出php 1. $url = 'http://www.sina.cn/abc/de.php?id=1'; $arr = ...

  6. Python 从大型csv文件中提取感兴趣的行

    帮妹子处理一个2.xG 大小的 csv文件,文件太大,不宜一次性读入内存,可以使用open迭代器. with open(filename,'r') as file # 按行读取 for line in ...

  7. python 从2个文件中提取不相同的内容并输出到第三个文件中

    #-*- coding: UTF-8 -*- import re import sys import os   str1=[] str2=[] str_dump=[] fa=open("A. ...

  8. 从txt中提取子域名

    import re DOMAIN =[] f = open('test.txt','r',encoding='UTF-8') w = open('domain.txt','w') for data i ...

  9. Python实现在给定整数序列中找到和为100的所有数字组合

    摘要:  使用Python在给定整数序列中找到和为100的所有数字组合.可以学习贪婪算法及递归技巧. 难度:  初级 问题 给定一个整数序列,要求将这些整数的和尽可能拼成 100. 比如 [17, 1 ...

随机推荐

  1. CF #324 DIV2 E题

    这题很简单,把目标位置排序,把目标位置在当前位置前面的往前交换,每次都是贪心选择第一个满足这样要求的数字. #include <iostream> #include <cstdio& ...

  2. Spark Streaming接收Kafka数据存储到Hbase

    Spark Streaming接收Kafka数据存储到Hbase fly spark hbase kafka 主要参考了这篇文章https://yq.aliyun.com/articles/60712 ...

  3. hibernate 普通字段延迟载入无效的解决的方法

    关联对象的延迟载入就不说了.大家都知道. 关于普通字段的延迟载入,尤其是lob字段,若没有延迟载入,对性能影响极大.然而简单的使用 @Basic(fetch = FetchType.LAZY) 注解并 ...

  4. Light oj 1138 - Trailing Zeroes (III) 【二分查找 &amp;&amp; N!中末尾连续0的个数】

    1138 - Trailing Zeroes (III) problem=1138"> problem=1138&language=english&type=pdf&q ...

  5. Python图像处理库PIL中图像格式转换(一)

    在数字图像处理中,针对不同的图像格式有其特定的处理算法. 所以,在做图像处理之前,我们须要考虑清楚自己要基于哪种格式的图像进行算法设计及事实上现.本文基于这个需求.使用python中的图像处理库PIL ...

  6. Atitit. C# java 的api 文件夹封装结构映射总结

    Atitit. C#  java 的api 文件夹封装结构映射总结 C# java ref System.Reflection System.Type. java.lang.ref concurren ...

  7. 到底什么是nandflash,norflash,sdram,emmc,rom,ram【转】

    本文转载自:http://blog.sina.com.cn/s/blog_6dd8f2b70101le26.html 最近被nandflash,norflash,sdram,emmc,rom,ram搞 ...

  8. poj 2288 Islands and Bridges ——状压DP

    题目:http://poj.org/problem?id=2288 状压挺明显的: 一开始写了(记忆化)搜索,但一直T: #include<iostream> #include<cs ...

  9. Coursera Algorithms week1 查并集 练习测验:3 Successor with delete

    题目原文: Given a set of n integers S = {0,1,…,N-1}and a sequence of requests of the following form: Rem ...

  10. html5 窗口之间的通信

    一般窗口通信分为三种: iframe嵌套:多个iframe之间通信. 父页面操作子页面元素:oFrame.contentWindow.document.body. 父页面调用子页面方法:oFrame. ...