A rustacean implementation of tldextract
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
.travis.yml
Cargo.toml
LICENSE
README.md

README.md

tldextract-rs

Travis license

A rustacean implementation of tldextract highly inspired by python's module tldextract by John Kurkowski. A tool to accurately separate the TLD from the registered domain and subdomains of a URL, using the Public Suffix List. This relys on the Public Suffix List to identify gTLDs and ccTLDs correctly as oppose to spliting the URL string by dots and guessing where the parts of interest to you are.

Requirements

Rust 1.13.0 or later is required.

On OS X and Windows, you may need to install the openssl runtime and headers to get the rust-openssl dependency to build. Instructions for that can be found here.

Installation

tldextract is available on crates.io. To use tldextract in your Rust program built with Cargo, add it as a dependency as follows:

    [dependencies]
    tldextract = {"*"}

Usage

Below is the simplest way to use tldextract:

    extern crate tldextract;
    use tldextract::tldextract::extract::TldExtract;
    
    fn main() {
        let url = "http://news.forums.bbc.co.uk";
        // Initiate a new TldExtract
        let tld_extractor = TldExtract::new(None, None);
        // call extract passing the URL string and get a tuple of results
        let (subdomain, domain, suffix) = tld_extractor.extract(url);
        println!("Subdomains: {:?}, Domain: {:?}, Suffix: {:?}",
                 subdomain,
                 domain,
                 suffix);
    }