Skip to content
首页/正文

下载civitai视频的脚本

主要步骤为以下:

  1. 获取页面内所有视频链接
  2. 存入 urls.txt 文件
  3. 执行 main.py 脚本

获取所有链接 ​

打开目标视频集合页面,使用console输入脚本来收集网址

以下用来获取,滚动进行收集

(function() {
  const allHrefs = new Set();
  
  // 创建可点击的悬浮按钮
  const indicator = document.createElement('div');
  Object.assign(indicator.style, {
    position: 'fixed',
    top: '20px',
    right: '20px',
    padding: '10px 16px',
    backgroundColor: 'rgba(0, 0, 0, 0.85)',
    color: '#fff',
    borderRadius: '8px',
    zIndex: '999999',
    fontSize: '14px',
    boxShadow: '0 4px 12px rgba(0,0,0,0.3)',
    cursor: 'pointer',
    userSelect: 'none',
    transition: 'transform 0.2s ease',
    fontFamily: 'sans-serif',
    border: '1px solid #4dabf7'
  });
  indicator.innerHTML = '已采集: <span style="color: #4dabf7; font-weight: bold;">0</span> 个 (点击停止并复制)';
  document.body.appendChild(indicator);

  const updateUI = (count) => {
    const span = indicator.querySelector('span');
    if (span) span.innerText = count;
    indicator.style.transform = 'scale(1.05)';
    setTimeout(() => indicator.style.transform = 'scale(1)', 100);
  };

  const collect = () => {
    const anchors = document.querySelectorAll('a[href*="/images/"], a[href*="/posts/"], a[href*="/models/"]');
    const newlyAdded = [];
    
    anchors.forEach(a => {
      try {
        const url = new URL(a.href);
        const cleanUrl = url.origin + url.pathname;
        // 如果是新链接,加入集合并记录本次新增
        if (!allHrefs.has(cleanUrl)) {
          allHrefs.add(cleanUrl);
          newlyAdded.push(cleanUrl);
        }
      } catch(e) {}
    });

    // 只有发现新链接时才更新 UI 和打印日志
    if (newlyAdded.length > 0) {
      updateUI(allHrefs.size);
      console.log(
        `%c[实时采集] 当前总计: ${allHrefs.size} 个 (+${newlyAdded.length})`,
        'color: #4dabf7; font-weight: bold;'
      );
      // 逐条打印新增的网址,方便核对
      newlyAdded.forEach((link, idx) => {
        console.log(`  ${allHrefs.size - newlyAdded.length + idx + 1}. ${link}`);
      });
    }
  };

  const observer = new MutationObserver(collect);
  observer.observe(document.body, { childList: true, subtree: true });
  collect();

  // 核心停止与复制逻辑
  const stopAndCopy = async () => {
    observer.disconnect();
    const result = Array.from(allHrefs).join('\n');
    const count = allHrefs.size;

    try {
      await navigator.clipboard.writeText(result);
      console.log(`%c✅ 采集完成!共 ${count} 个链接,已成功复制到剪贴板。`, 'color: #40c057; font-weight: bold; font-size: 13px;');
    } catch (err) {
      const textArea = document.createElement("textarea");
      textArea.value = result;
      document.body.appendChild(textArea);
      textArea.select();
      document.execCommand('copy');
      document.body.removeChild(textArea);
      console.log(`%c✅ 采集完成(降级模式)!共 ${count} 个链接,已复制到剪贴板。`, 'color: #40c057; font-weight: bold; font-size: 13px;');
    }

    if (document.body.contains(indicator)) {
      document.body.removeChild(indicator);
    }
    delete window.__stopCollection;
  };

  indicator.addEventListener('click', stopAndCopy);
  window.__stopCollection = () => {
    observer.disconnect();
    if (document.body.contains(indicator)) document.body.removeChild(indicator);
    return Array.from(allHrefs).join('\n');
  };

  console.log('%c🚀 开始监控... 滚动页面时控制台将实时输出新增网址与序号。完成后点击右上角悬浮框即可复制。', 'color: #fcc419; font-weight: bold;');
})();

点击按钮停止收集脚本

存入URLS.TXT ​

脚本会在停止后复制到剪切板,你只需要创建文本文件后粘贴

最后执行python脚本

视频就会下载到目录里面