DatafetchPro
    1776920270631_hez22.webp
    Apr 23, 20265 min read18 views

    Copy Website Tables Instantly (CSV & Clipboard)

    Easily copy or export any website table to CSV or Excel in one click. Save time, avoid messy formatting, and turn data into usable files instantly.

    Turn Any Website Table Into Copyable Data (In One Click)

    Ever landed on a website with a table full of useful data… and then realized you can’t easily copy it?

    You try selecting it → messy formatting.
    You paste it → everything breaks.
    You download it → not even an option.

    Yeah… frustrating.

    So instead of fighting with tables, this tiny script does the job for you.


    What This Script Does

    Once you install it, every table on any website gets two simple buttons:

    • 📋 Copy → instantly copies the table into clean, spreadsheet-ready format
    • 📥 Export CSV → downloads the table as a file you can open in Excel or Google Sheets

    No setup. No learning curve. Just click and go.


    Why It’s Actually Useful

    This isn’t just a “nice to have” thing — it saves real time.

    • Doing research? Grab data instantly
    • Working with reports? Export in seconds
    • Collecting leads? Copy clean rows without fixing formatting
    • Browsing stats or financial data? Download and analyze right away

    It turns static tables into usable data.


    Real Example

    Let’s say you open a page with statistics or historical data.

    Normally:

    • You highlight rows
    • Paste into Excel
    • Fix columns manually
    • Waste 5–10 minutes

    With this script:

    • Click Copy → paste → done
      or
    • Click Export CSV → open file → done

    That’s it.


    Where It Works

    Almost everywhere:

    • Data tables
    • Pricing tables
    • Stats pages
    • Reports
    • Listings

    If there’s a table on the page, it works.


    What Makes It Better

    • Works automatically on every site
    • Handles dynamic pages (even scrolling content)
    • Clean output (no broken formatting)
    • Lightweight and fast

    It doesn’t try to do too much — just solves one annoying problem really well.


    Perfect For

    • Researchers
    • Freelancers
    • Marketers
    • Data collectors
    • Anyone tired of messy copy-paste



    // ==UserScript==
    // @name Table Exporter (Copy & CSV)
    // @namespace http://tampermonkey.net/
    // @version 1.0
    // @description Adds Copy and Export CSV buttons to every table on the page.
    // @author Gemini
    // @match *://*/*
    // @grant none
    // ==/UserScript==

    (function() {
    'use strict';

    // Style for the buttons
    const style = document.createElement('style');
    style.innerHTML = `
    .tm-table-controls {
    margin-bottom: 5px;
    display: flex;
    gap: 8px;
    }
    .tm-btn {
    padding: 4px 8px;
    background: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-family: sans-serif;
    color: #333;
    }
    .tm-btn:hover { background: #e0e0e0; }
    `;
    document.head.appendChild(style);

    function tableToCSV(table) {
    const rows = Array.from(table.querySelectorAll('tr'));
    return rows.map(row => {
    const cells = Array.from(row.querySelectorAll('th, td'));
    return cells.map(cell => {
    let data = cell.innerText.replace(/"/g, '""').trim();
    return `"${data}"`;
    }).join(',');
    }).join('\n');
    }

    function downloadCSV(csv, filename) {
    const csvFile = new Blob([csv], { type: 'text/csv' });
    const downloadLink = document.createElement('a');
    downloadLink.download = filename;
    downloadLink.href = window.URL.createObjectURL(csvFile);
    downloadLink.style.display = 'none';
    document.body.appendChild(downloadLink);
    downloadLink.click();
    document.body.removeChild(downloadLink);
    }

    function addButtons(table) {
    if (table.dataset.tmProcessed) return;
    table.dataset.tmProcessed = "true";

    const container = document.createElement('div');
    container.className = 'tm-table-controls';

    // Copy Button
    const copyBtn = document.createElement('button');
    copyBtn.innerText = '📋 Copy';
    copyBtn.className = 'tm-btn';
    copyBtn.onclick = () => {
    const csv = tableToCSV(table).replace(/"/g, ''); // Cleaner for clipboard
    navigator.clipboard.writeText(csv.replace(/,/g, '\t'));
    copyBtn.innerText = '✅ Copied!';
    setTimeout(() => copyBtn.innerText = '📋 Copy', 2000);
    };

    // Export Button
    const exportBtn = document.createElement('button');
    exportBtn.innerText = '📥 Export CSV';
    exportBtn.className = 'tm-btn';
    exportBtn.onclick = () => {
    const csv = tableToCSV(table);
    downloadCSV(csv, 'table-export.csv');
    };

    container.appendChild(copyBtn);
    container.appendChild(exportBtn);
    table.parentNode.insertBefore(container, table);
    }

    // Run on existing tables
    document.querySelectorAll('table').forEach(addButtons);

    // Watch for tables added dynamically (AJAX/SPA)
    const observer = new MutationObserver(() => {
    document.querySelectorAll('table').forEach(addButtons);
    });
    observer.observe(document.body, { childList: true, subtree: true });

    })();

    /*
    Example Pages

    https://www.bls.gov/news.release/cpi.t01.htm
    https://www.baseball-reference.com/players/o/ohtansh01.shtml
    https://finance.yahoo.com/quote/AAPL/history/?

    */
    0