What is Alexa Ranking?

Alexa ranking is a collection of domain/url listing which provide ranking to the domain and URL on the basis of its priority and usage.
This top listing of clean domains helped lot of folks to understand the URL/Domains popularity, some people also used alexa ranking as a tool to identify genuine website. Like if Alexa ranking is good means lot of people are using it and its popular so its ok to trust that particular URL/Domain.

But, Alexa rank stopped its operations in May 2022. It had been around for 25 years and was owned by Amazon. Alexa Rank was well-known for providing insights into website popularity and competition, making it a valuable resource for many users. However, as of May 2022, the service is no longer available.

If Alexa ranking is no more then how to check alexa ranking?

From UI based there are various tools available if you search it, but to check programmatically Python API we can use tranco-listing from tranco tranco-list.eu.

What exactly Tranco listing provides?

Tranco provides csv list of top 1million Domains, and its relative ranking, we can leverage this ranking using python.

Demo:

#code is generated by something, if you know you know.
#copy and paste it to your module
import datetime
import os
import requests
import zipfile
import csv

# URL for Tranco top 1 million domain list
url = "https://tranco-list.eu/top-1m.csv.zip"
local_file = "top-1m.csv"

# Function to download and extract the CSV file
def download_csv():
    response = requests.get(url)
    with open("top-1m.zip", "wb") as file:
        file.write(response.content)

    with zipfile.ZipFile("top-1m.zip", "r") as zip_ref:
        zip_ref.extractall()
        
    os.remove("top-1m.zip")

# Check if the CSV file exists and is updated today
def is_csv_updated():
    if not os.path.exists(local_file):
        return False

    modified_date = datetime.datetime.fromtimestamp(os.path.getmtime(local_file)).date()
    current_date = datetime.datetime.now().date()
    if modified_date != current_date:
        return False

    return True

# Fetch the Tranco top 1 million domain list
if not is_csv_updated():
    print("Downloading the Tranco top 1 million domain list...")
    download_csv()
    print("Download complete!")

# Read the CSV file and check if the provided URL is present
def check_domain_rank(url):
    with open(local_file, "r") as csv_file:
        csv_reader = csv.reader(csv_file)
        for rank, domain in csv_reader:
            if domain in url:
                print(f"The '{url}' domain is ranked #{rank} in the Tranco top 1 million list.")
                return

    print(f"The domain '{url}' is not found in the Tranco top 1 million list.")

# Test the script with a sample URL
provided_url = "adobe.com"
check_domain_rank(provided_url)

Output:

PS F:> python tranco.py

Downloading the Tranco top 1 million domain list…
Download complete!
The domain 'adobe.com' is ranked #46 in the Tranco top 1 million list.

On Second run, csv file will not get downloaded it will use the local copy, but when local copy of top domain list csv get 24 hours old it will fetch the fresh copy. We are doing this to avoid efforts of downloading csv multiple time.

PS F:> python tranco.py
The 'test.com' domain is ranked #70 in the Tranco top 1 million list.


PS F:> python tranco.py
The 'lol.com' domain is ranked #327163 in the Tranco top 1 million list.

Tranco is also thirdparty api just like alexa ranking, user may have to check correctness of api once in while.

Thank you!! 😀