网页文案提取工具

方法1:

1. 在下方输入框中输入您想提取文案的网页网址

2. 点击"加载网站"按钮

3. 等待网页加载完成,可能需要加载3-5秒

4. 网页加载完成后,您可以滑动页面确保内容完全加载完成

5. 您可以点击加载完成后的页面右上角的获取页面文案按钮来获取所需文案

方法2:

1. 在新窗口,打开你需要获取文案的网页

2. 按下F12打开开发者工具

3. 在console或者控制台中输入以下代码

4. 点击加载在的页面右上角的获取页面文案按钮来获取所需文案

(function() {
    'use strict';
    // 按句子分隔文本的函数
    function splitSentences(text) {
        // 使用正则表达式按句号、问号、感叹号等符号分割句子
        const sentences = text.split(/(?<=[.!?])\s+/);
        return sentences.filter(sentence => sentence.trim().length > 0); // 过滤空句子
    }

    function countText() {
        // 用于将文案拼接为字符串
        let concatenatedText = '';
        // 获取网页中的所有文本内容
        const text = document.body.innerText || document.body.textContent;
        // 按段落分割文本
        const paragraphs = text.split(/\n+/).filter(p => p.trim().length > 0); // 去除空段落
        // 遍历每个段落,按句子拆分
        paragraphs.forEach((paragraph, idx) => {
            const sentences = splitSentences(paragraph);
            // 改用for循环 在遇到获取页面文案时,跳过
            for (let i = 0; i < sentences.length; i++) {
                if (sentences[i].includes('获取页面文案')) {
                    continue;
                } else {
                    concatenatedText += `
                        <li>${sentences[i]}</li>
                    `;
                }
            }
        });
        // 去掉最后的多余分隔符
        concatenatedText = concatenatedText.trim().replace(/--\s*$/, '');
        // 字符串拼接html
        concatenatedText = `<html>
            <body>
                <div>
                    <h2>去除空白字符后的总字符数:${text.replace(/\s+/g, '').length}</h2>
                </div>

                <div>
                    <ol>
                        ${concatenatedText}
                    </ol>
                </div>
            </body>
        </html>`;
        // 创建一个新的窗口
        var newWindow = window.open();
        // 将拼接的 HTML 写入新页面
        newWindow.document.write(concatenatedText);
        // 关闭文档流,完成页面渲染
        newWindow.document.close();
    }

    // 创建按钮并添加到页面右上角
    function createButton() {
        const button = document.createElement('button');
        button.innerText = '获取页面文案';
        button.style.position = 'fixed';
        button.style.top = '20px';
        button.style.right = '20px';
        button.style.padding = '10px 20px';
        button.style.fontSize = '14px';
        button.style.backgroundColor = '#007BFF';
        button.style.color = '#fff';
        button.style.border = 'none';
        button.style.borderRadius = '5px';
        button.style.cursor = 'pointer';
        button.style.zIndex = '99999999';
        // 添加按钮点击事件
        button.addEventListener('click', function() {
            countText();
        });
        // 将按钮添加到页面
        document.body.appendChild(button);
    }

    // 初始字符计数
    createButton();
})();