TLDExtract 项目使用教程

TLDExtract 项目使用教程

TLDExtract[DEPRECATED] Library for extraction of domain parts e.g. TLD. Domain parser that uses Public Suffix List项目地址:https://gitcode.com/gh_mirrors/tld/TLDExtract

1. 项目的目录结构及介绍

TLDExtract 项目的目录结构如下:

TLDExtract/
├── README.md
├── LICENSE
├── tldextract/
│   ├── __init__.py
│   ├── tldextract.py
│   ├── cache/
│   └── utils/
├── tests/
│   ├── __init__.py
│   └── test_tldextract.py
├── setup.py
└── requirements.txt
  • README.md: 项目说明文档。
  • LICENSE: 项目许可证文件。
  • tldextract/: 项目的主要代码目录。
    • __init__.py: 初始化文件。
    • tldextract.py: 核心功能实现文件。
    • cache/: 缓存文件目录。
    • utils/: 工具函数目录。
  • tests/: 测试代码目录。
    • __init__.py: 初始化文件。
    • test_tldextract.py: 测试用例文件。
  • setup.py: 项目安装脚本。
  • requirements.txt: 项目依赖文件。

2. 项目的启动文件介绍

项目的启动文件是 tldextract/tldextract.py。该文件包含了 TLDExtract 类的定义,主要功能是解析 URL,提取出子域名、域名和公共后缀。

# tldextract/tldextract.py

import os
import re
import urllib.request
from collections import namedtuple

ExtractResult = namedtuple('ExtractResult', ['subdomain', 'domain', 'suffix', 'is_private'])

class TLDExtract:
    def __init__(self, suffix_list_urls=None, cache_dir=None):
        # 初始化代码
        pass

    def extract(self, url):
        # 解析 URL 的代码
        pass

3. 项目的配置文件介绍

项目的配置文件主要是 setup.pyrequirements.txt

  • setup.py: 用于安装项目的脚本,定义了项目的元数据和依赖。
# setup.py

from setuptools import setup, find_packages

setup(
    name='tldextract',
    version='5.1.2',
    packages=find_packages(),
    install_requires=[
        # 依赖列表
    ],
    author='John Kurkowski',
    author_email='john.kurkowski@gmail.com',
    description='Accurately separates a URL\'s subdomain, domain, and public suffix using the Public Suffix List (PSL)',
    license='BSD-3-Clause',
    keywords='tld domain subdomain url parse extract urlparse urlsplit public suffix list publicsuffix publicsuffixlist',
    url='https://github.com/layershifter/TLDExtract',
)
  • requirements.txt: 列出了项目运行所需的依赖包。
# requirements.txt

requests>=2.25.1
urllib3>=1.26.3

通过以上配置文件,可以确保项目在不同的环境中正确安装和运行。

TLDExtract[DEPRECATED] Library for extraction of domain parts e.g. TLD. Domain parser that uses Public Suffix List项目地址:https://gitcode.com/gh_mirrors/tld/TLDExtract

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

包力文Hardy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值