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 ...
随机推荐
- ZooKeeper可视化Web管理工具收集(待实践)
原来ZooKeeper是有Web管理后台的.但是仅限于操作ZooKeeper的数据,如果要监控性能,估计要借助Nagios去配合. 这些工具应该ZK UI最好用,下面是收集的一些工具安装教程: htt ...
- 循环A表,根据查询结果,更新A表字段
create or replace procedure prc_user_xtzx_match(p_flag out varchar2) IS xingming_match_loginname ); ...
- v$open_cursor中的相同record
之前在查看v$open_cursor的时候,发现很多相同的record. 让我很疑惑, sid saddr sql_id 都相同,我就想 这不是一个cursor吗? 那为什么在open_cursor中 ...
- HDU 2767-Proving Equivalences(强联通+缩点)
题目地址:pid=2767">HDU 2767 题意:给一张有向图.求最少加几条边使这个图强连通. 思路:先求这张图的强连通分量.假设为1.则输出0(证明该图不须要加边已经是强连通的了 ...
- vim快速操作
简明 VIM 练级攻略 vim的学习曲线相当的大(参看各种文本编辑器的学习曲线),所以,如果你一开始看到的是一大堆VIM的命令分类,你一定会对这个编辑器失去兴趣的.下面的文章翻译自<Learn ...
- PHP5+标准函数库观察者之实现
PHP的观察者设计模式实现相对简单,可是PHP5+版本号中已经有标准库类库支持,我们仅仅需简单继承并实现就能够了. 观察者:实现标准接口类库SplSubject. 一个注冊方法:attach.一个取消 ...
- Project Euler:Problem 33 Digit cancelling fractions
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplif ...
- saltstack结合Elasticsearch来做salt运行结果展现
salt尽管好用可是机器管理的越来越多,通过cli的结果输出方式查看运行结果越来越多不能满足我的需求.并且作为一个推动运维自己主动化的攻城狮,使用这样的人眼查看运行结果的方式简直土到掉渣.尽管别人看起 ...
- light oj1074
Description The people of Mohammadpur have decided to paint each of their houses red, green, or blue ...
- CMDBuild安装
近日来,老板要在内部部署一套IT资产管理系统,要笔者去调研一下,测试了GLPI.OCSNG(没记错吧)和CMDBuild之后,发现还是CMDBuild的功能较为强大,虽然暂时不具备SNMP之类的工具, ...