安装

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. gap lock/next-key lock浅析Basic-Paxos协议日志同步应用

    http://www.cnblogs.com/renolei/p/4673842.html 当InnoDB在判断行锁是否冲突的时候, 除了最基本的IS/IX/S/X锁的冲突判断意外, InnoDB还将 ...

  2. mybatis+mysql返回插入的主键,参数只是提供部分参数

    mybatis+mysql返回插入的主键,参数只是提供部分参数 <insert id="insertByChannelIdOpenid" useGeneratedKeys=& ...

  3. [CSS3] Use Sticky Positioning for Section Headers

    We can take advantage of sticky positioning to keep a section header at the top of the page while th ...

  4. nyoj 1238 最少换乘 (河南省第八届acm程序设计大赛)

    题目1238 题目信息 执行结果 本题排行 pid=1238" style="text-decoration:none; color:rgb(55,119,188)"&g ...

  5. android測试工具MonkeyRunner--google官网翻译

    近期在复习之前的笔记,在回想MonkeyRunner时看了看google官网的内容,写得不错.就翻译出来分享下.事实上google官网真是一个学习的好地方. 基础知识 MonkeyRunner工具提供 ...

  6. HDU 5538/ 2015长春区域 L.House Building 水题

    题意:求给出图的表面积,不包括底面 #include<bits/stdc++.h> using namespace std ; typedef long long ll; #define ...

  7. 微信小程序初探(二、分页数据请求)

    大家好 波哥小猿又来啦[斜眼笑],昨天咱们讲了微信小程序简单数据请求,有没有照着教程实现请求的同学们啦 实现的同学举个爪[笑脸].哈哈,好了不扯犊子啦,我相信有的同学已经实现了简单的数据请求,没有实现 ...

  8. Codeforces--630N--Forecast(方程求解)

    N - Forecast Crawling in process... Crawling failed Time Limit:500MS     Memory Limit:65536KB     64 ...

  9. 欧拉函数&&欧拉定理

    定义和简单性质 欧拉函数在OI中是个非常重要的东西,不知道的话会吃大亏的. 欧拉函数用希腊字母φ表示,φ(N)表示N的欧拉函数. 对φ(N)的值,我们可以通俗地理解为小于N且与N互质的数的个数(包含1 ...

  10. Swift备忘录

    Swift 备忘录 2015-4 一.简介 1.Swift 语言由苹果公司在2010年7月开始设计,在 2014 年6月推出,在 2015 年 12 月 3 日开源 2.特点(官方): (1)苹果宣称 ...