python 从给定的URL中提取顶级域名(TLD)
安装
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)的更多相关文章
- Java获取URL中的顶级域名domain的工具类
方式一: import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; import jav ...
- 飘逸的python - 用urlparse从url中抽离出想要的信息
最近有个需求,要检测配置中的那些url的域名是否都正常,即是否都能ping通. 不过配置中url格式是这样的 http://www.something.com:1234/ . 要ping的是www.s ...
- python 从url中提取域名和path
使用Python 内置的模块 urlparse from urlparse import * url = 'https://docs.google.com/spreadsheet/ccc?key=bl ...
- 从url中提取参数名和参数值(转)
在已知参数名的情况下,获取参数值,使用正则表达式能很容易做到.js的实现方法如下: function getValue(url, name) { var reg = new RegExp('(\\?| ...
- 从一个标准URL中提取文件的扩展名
例如:http://www.sina.cn/abc/de.php?id=1 提出php 1. $url = 'http://www.sina.cn/abc/de.php?id=1'; $arr = ...
- Python 从大型csv文件中提取感兴趣的行
帮妹子处理一个2.xG 大小的 csv文件,文件太大,不宜一次性读入内存,可以使用open迭代器. with open(filename,'r') as file # 按行读取 for line in ...
- python 从2个文件中提取不相同的内容并输出到第三个文件中
#-*- coding: UTF-8 -*- import re import sys import os str1=[] str2=[] str_dump=[] fa=open("A. ...
- 从txt中提取子域名
import re DOMAIN =[] f = open('test.txt','r',encoding='UTF-8') w = open('domain.txt','w') for data i ...
- Python实现在给定整数序列中找到和为100的所有数字组合
摘要: 使用Python在给定整数序列中找到和为100的所有数字组合.可以学习贪婪算法及递归技巧. 难度: 初级 问题 给定一个整数序列,要求将这些整数的和尽可能拼成 100. 比如 [17, 1 ...
随机推荐
- N天学习一个linux命令之ip
用途 show / manipulate routing, devices, policy routing and tunnels 用法 通用格式 ip [ OPTIONS ] OBJECT { CO ...
- [数据结构与算法]排序算法(Python)
1.直接插入排序 给定一个数组后,从第二个元素开始,如果比第一个小,就跟他交换位置,否则不动:第三个元素如果比第二个小,把第三个跟第二个交换位置,在把第二个与第一个比较:..... def inser ...
- iOS: 导航栏显示默认后退按钮
要显示系统默认的后退按钮(非自定义)的语句如下: [[self navigationController] setNavigationBarHidden:NO animated:YES];self.n ...
- 2015 测试赛 同构 hihoCoder
题目1 : 同构 时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定2个树A和B,保证A的节点个数>=B的节点个数. 现在你需要对树A的边进行二染色. 一个好的染色 ...
- nyoj891(区间上的贪心)
题目意思: 给一些闭区间,求最少须要多少点,使得每一个区间至少一个点. http://acm.nyist.net/JudgeOnline/problem.php?pid=891 例子输入 4 1 5 ...
- 阿伦 凯 Alan Kay 面向对象编程思想创始人
The best way to predict the future is to invent it. 预测未来最好的办法就是创造它.
- 向Java枚举类型中加入新方法
除了不能继承enum之外,可将其看做一个常规类.甚至能够有main方法. 注意:必须先定义enum实例.实例的最后有一个分号. 以下是一个样例:返回对实例自身的描写叙述,而非默认的toString返回 ...
- oc34--instancetype和id的区别
// Person.h #import <Foundation/Foundation.h> @interface Person : NSObject @property int age; ...
- poj3041——最小点覆盖
Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N g ...
- 【SDOI 2010】 魔法猪学院
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1975 [算法] A*求k短路 [代码] #include<bits/stdc+ ...