Skip to main content

A tool to count words in the main content of web pages, ignoring cookie banners and other non-content elements.

Project description

URL Word Counter

A Python tool that counts words in the main content of web pages, ignoring cookie banners, headers, and footers. It uses Selenium with a headless Chrome browser to properly render JavaScript-heavy websites.

Features

  • Extracts main content from web pages
  • Ignores cookie banners, headers, and footers
  • Handles JavaScript-rendered content
  • Provides word count and content preview
  • Simple command-line interface

Installation

Prerequisites

  • Python 3.8 or higher
  • Google Chrome (required for Selenium)

Option 1: Install from source

  1. Clone this repository:

    git clone <repository-url>
    cd url-word-counter
    
  2. Install the package in development mode:

    pip install -e .
    

Option 2: Install directly from GitHub

pip install git+https://github.com/yourusername/url-word-counter.git

Option 3: Install with pip

pip install url-word-counter

Usage

Command Line Interface

After installation, you can run the URL Word Counter from the command line:

url-word-counter [URL] [--no-headless]
  • URL: (Optional) The URL to analyze. If not provided, you'll be prompted to enter one.
  • --no-headless: (Optional) Run the browser in non-headless mode (visible browser window).

Example:

url-word-counter https://www.example.com/

Python API

You can also use the URL Word Counter in your Python code:

from url_word_counter import URLWordCounter

# Initialize the counter
counter = URLWordCounter()

# Get word count for a URL
word_count, preview, error = counter.get_word_count("https://www.example.com/")

if error:
    print(f"Error: {error}")
else:
    print(f"Word count: {word_count:,}")
    print(f"Preview: {preview}")

# Don't forget to close the browser when done
counter.close()

Example

🛠️  Advanced URL Word Counter (with JavaScript support)
============================================================

🚀 Initializing browser...

🌐 Enter URL (or 'q' to quit): https://www.example.com/

🔍 Analyzing https://www.example.com/...

📊 Word count (main content only): 1,234

📝 Content preview: This is a preview of the extracted content from the webpage...

How It Works

The script uses:

  • Selenium WebDriver with Chrome in headless mode
  • BeautifulSoup for HTML parsing
  • Smart content extraction that focuses on the main content area
  • Word counting that ignores HTML tags and scripts

Requirements

  • Python 3.8+
  • Google Chrome
  • ChromeDriver (automatically installed by webdriver-manager)

License

MIT


Lovable Project

Project info

URL: https://lovable.dev/projects/87abc578-1123-4e3e-8c3e-44d646a171db

How can I edit this code?

There are several ways of editing your application.

Use Lovable

Simply visit the Lovable Project and start prompting.

Changes made via Lovable will be committed automatically to this repo.

Use your preferred IDE

If you want to work locally using your own IDE, you can clone this repo and push changes. Pushed changes will also be reflected in Lovable.

The only requirement is having Node.js & npm installed - install with nvm

Follow these steps:

# Step 1: Clone the repository using the project's Git URL.
git clone <YOUR_GIT_URL>

# Step 2: Navigate to the project directory.
cd <YOUR_PROJECT_NAME>

# Step 3: Install the necessary dependencies.
npm i

# Step 4: Start the development server with auto-reloading and an instant preview.
npm run dev

Edit a file directly in GitHub

  • Navigate to the desired file(s).
  • Click the "Edit" button (pencil icon) at the top right of the file view.
  • Make your changes and commit the changes.

Use GitHub Codespaces

  • Navigate to the main page of your repository.
  • Click on the "Code" button (green button) near the top right.
  • Select the "Codespaces" tab.
  • Click on "New codespace" to launch a new Codespace environment.
  • Edit files directly within the Codespace and commit and push your changes once you're done.

What technologies are used for this project?

This project is built with:

  • Vite
  • TypeScript
  • React
  • shadcn-ui
  • Tailwind CSS

How can I deploy this project?

Simply open Lovable and click on Share -> Publish.

Can I connect a custom domain to my Lovable project?

Yes, you can!

To connect a domain, navigate to Project > Settings > Domains and click Connect Domain.

Read more here: Setting up a custom domain

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sharkpress_word_counter-1.0.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sharkpress_word_counter-1.0.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file sharkpress_word_counter-1.0.0.tar.gz.

File metadata

  • Download URL: sharkpress_word_counter-1.0.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for sharkpress_word_counter-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2bd7d5c76f289528a5f1041bb3acf3d2c15dc64489bb5a2bf934af7d75dbb444
MD5 10bcbc247687dc890373db4714536484
BLAKE2b-256 2a1873eaa91cb677b2517036c41e03a4e5d39e984e2d2005e86fcf88d262c236

See more details on using hashes here.

File details

Details for the file sharkpress_word_counter-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sharkpress_word_counter-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b9bc1aae63bdca117173404f2d893f67f3bd8aa55dc30c0a4a400cec2b7422e
MD5 91e0e8601e32fdeb6cf047553504e3ca
BLAKE2b-256 05d3cb73fd3a11f48f0f4ac2744dee4ba8f21facc7e7b373ef21f155cec24138

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page