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
-
Clone this repository:
git clone <repository-url> cd url-word-counter
-
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters