安装

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. 洛谷—— P1379 八数码难题

    https://daniu.luogu.org/problem/show?pid=1379 题目描述 在3×3的棋盘上,摆有八个棋子,每个棋子上标有1至8的某一数字.棋盘中留有一个空格,空格用0来表示 ...

  2. 【树状数组】POJ 2155 Matrix

    附一篇经典翻译,学习 树状数组  http://www.hawstein.com/posts/binary-indexed-trees.html /** * @author johnsondu * @ ...

  3. 尝试create tech team

    自从上一家公司之后,我很少有机会去带一些新人(公司一般都招一些技术独立性的工程师),特别是经验不是特别多的新小伙伴.在如今管理扁平化的公司,我正逐渐搭建自己的小team,并试图让团队成员快速融入并成长 ...

  4. Python游戏server开发日记(一)目标

    到了新的环境.老大让我有空研究下一代server技术,作为一个长期任务. 新的server想达到的目标: 1.分布式系统,对象(Entity)之间的关系类似于Actor模型. 2.逻辑服务,是单进程. ...

  5. STL_算法_填充新值(fill、fill_n、generate、generate_n)

    C++ Primer 学习中... 简单记录下我的学习过程 (代码为主) 全部容器适用 fill(b,e,v)             //[b,e)   填充成v fill_n(b,n,v)     ...

  6. oc52--autorelease1

    // // main.m /* autorelease也是用于内存管理的,给对象发送autorelease消息就会把对象放入autoreleasepool这个池子中,当池子销毁的时候会对池子里面的所有 ...

  7. LA6878

    区间dp dp[i][j]存i->j区间的所有取值 然后枚举分割点,枚举两个存的值,分别运算存储. 看见这种不确定分割顺序,两个区间合并的情况,就要用区间dp. #include<bits ...

  8. 【原创分析帖】据说Google内部有史以来最难的一道面试题

    逛技术平台的时候,刷到一道算法题,一眼看去,就被其开头吸引了: 摘自知乎某 Google 分布式大神的一道题,技术是Google内部出的有史以来最难的一道题 嗯,距离下班还有一段时间,就看看把. 题目 ...

  9. Nginx代理配置-centos6.10版

    nginx代理配置 cd /etc/nginx/init.d vi default.conf 添加: upstream server1{ server 192.168.125.128:8100 wei ...

  10. CodeForces 680A&680B&680C&680D Round#356

    昨天晚上实在是=_=困...(浪了一天)就没有去打Codeforces 中午醒来看看题,还不太难. A题:模拟(水题 3minAC) // by Sirius_Ren #include <cst ...