小红书下载图片、文章

循环打开页面链接

  1. // ==UserScript==
  2. // @name xiaohongshu download images and record links
  3. // @name:zh-CN 小红书下载图片、文章
  4. // @namespace http://yourwebsite.com
  5. // @version 1.0
  6. // @license MIT
  7. // @description Download images and videos from new version weibo UI webpage.
  8. // @description:zh-CN 循环打开页面链接
  9. // @author Your Name
  10. // @match https://www.xiaohongshu.com/explore/*
  11. // @grant GM_download
  12. // @require https://cdnjs.cloudflare.com/ajax/libs/jszip/3.9.1/jszip.min.js
  13. // @require https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18. // 等待页面加载完毕
  19. window.addEventListener('load', function() {
  20. // 获取包含文本内容的<div>元素
  21. var divElement = document.getElementById('detail-desc');
  22. var titleElement = document.getElementById('detail-title');
  23. // 获取<div>元素中的文本内容
  24. var textContent = divElement.textContent;
  25. // 获取<div>元素中的文本内容
  26. var titleContent = "#"+titleElement.textContent+"#";
  27. // 创建一个Blob对象并保存到本地文件
  28. var blob = new Blob([titleContent+textContent], { type: 'text/plain' });
  29. var a = document.createElement('a');
  30. a.href = window.URL.createObjectURL(blob);
  31. a.download = 'text_content.txt'; // 文件名
  32. a.style.display = 'none';
  33. document.body.appendChild(a);
  34. a.click();
  35. document.body.removeChild(a);
  36.  
  37. var elements = document.querySelectorAll('.swiper-slide');
  38. var imageUrls = [];
  39.  
  40. elements.forEach(function(element, index) {
  41. var styleAttribute = element.getAttribute('style');
  42. var matches = styleAttribute.match(/background-image:\s*url\((['"]?)(.*?)\1\)/);
  43.  
  44. if (matches && matches.length > 2) {
  45. var imageUrl = matches[2];
  46. var fileName = 'image_' + index + '.jpg'; // 图片文件名,可以根据需要修改
  47.  
  48. // 使用 GM_download 下载图片
  49. GM_download({
  50. url: imageUrl,
  51. name: fileName,
  52. onerror: function(error) {
  53. console.error('下载图片失败:', error);
  54. },
  55. onload: function() {
  56. console.log('下载图片成功:', fileName);
  57. }
  58. });
  59. }
  60. });
  61.  
  62. console.log('提取的图片URL:', imageUrls);
  63.  
  64.  
  65. // 获取视频元素
  66. var videoElement = document.querySelector('video');
  67.  
  68. if (videoElement) {
  69. var videoUrl = videoElement.src;
  70. // 触发下载
  71. GM_download({
  72. url: videoUrl,
  73. name: 'video.mp4', // 下载文件名
  74. onload: function() {
  75. console.log('视频下载完成');
  76. },
  77. onerror: function(error) {
  78. console.error('视频下载失败:', error);
  79. }
  80. });
  81. }
  82. });
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91. })();
  92.  
  93.  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址