(js)通过js批量下载下载所有ChatGPT(文心一言示例)查询后的结果

(js)通过js批量下载下载所有ChatGPT(文心一言示例)查询后的结果

    正在检查是否收录...

因工作中需要用到ChatGPT,而gpt查询后的结果只能一个一个复制,查询的条目多的时候就比较麻烦,所以在这记录我的解决方案

一、通过脚本下载结果

以文心一言为例

1.首先是f12或右键查看元素找到对应块的元素

tps:文心一言会打开debug模式,可参考下图位置停用debug并刷新


可以看到文心一言的元素的类名

2.然后获取内容(注意文心一言的后回答的在前面所以我用unshift

function getContent(){ let content=document.querySelectorAll('.custom-html'),conArr=[]; for(i of content){ let text=i.textContent; conArr.unshift(text); } return conArr; } 

3.创建下载,设置名称格式这里我用json格式,创建链接,触发点击下载

function downloadContent(){ let name='查询结果_'+Math.floor(Math.random()*1000000)+'.json'; let blob = new Blob([JSON.stringify(getContent())]); // 创建 blob 对象 let link = document.createElement("a"); link.href = URL.createObjectURL(blob); // 创建一个 URL 对象并传给 a 的 href link.download = name; // 设置下载的默认文件名 link.click(); } 

4.将上述代码整合复制到控制台下载,或是放入油猴脚本中使用(推荐,可重复使用),油猴脚本如下几种:

推荐暴力猴和篡改猴(Tampermonkey)

最后

控制台代码

function getContent(){ let content=document.querySelectorAll('.custom-html'),conArr=[]; for(i of content){ let text=i.textContent; conArr.unshift(text); } return conArr; } (function downloadContent(){ let name='查询结果_'+Math.floor(Math.random()*1000000)+'.json'; let blob = new Blob([JSON.stringify(getContent())]); // 创建 blob 对象 let link = document.createElement("a"); link.href = URL.createObjectURL(blob); // 创建一个 URL 对象并传给 a 的 href link.download = name; // 设置下载的默认文件名 link.click(); }()) 

油猴代码(注意@namespace不要与其他脚本重复)

// ==UserScript== // @name 下载文本 - baidu.com // @namespace downloadContent Scripts // @match https://yiyan.baidu.com/ // @grant none // @version 1.0 // @author --lSir // @description 2024/1/25 // ==/UserScript== //获取内容 function getContent(){ let content=document.querySelectorAll('.custom-html'),conArr=[]; for(i of content){ let text=i.textContent; conArr.unshift(text); } return conArr; } //下载 function downloadContent(){ let name='查询结果_'+Math.floor(Math.random()*1000000)+'.json'; let blob = new Blob([JSON.stringify(getContent())]); // 创建 blob 对象 let link = document.createElement("a"); link.href = URL.createObjectURL(blob); // 创建一个 URL 对象并传给 a 的 href link.download = name; // 设置下载的默认文件名 link.click(); } //创建按钮并绑定事件 function createBox(){ let box=document.createElement('div'); box.classList.add("down_box"); box.innerHTML=`<button id="download">点击下载</button>` let myStyle = document.createElement('style'); myStyle.textContent='.down_box{width:auto;position:fixed; top:100px; right:2em;z-index:2147483647; font-size:14px;text-align: center;background-color: aliceblue;margin:20px auto;} #download{color:#fff;border:0;width:6em;height:3em;background-color:#2196f3;}' let doc = document.head || document.documentElement; doc.appendChild(myStyle); document.body.appendChild(box); let downloadBut=document.querySelector('#download') downloadBut.onclick=function(){ downloadContent() } } window.onload=(function(){ createBox() } ) 

当然,也可以CTRL+A,CTRL+C全部复制下来,然后通过程序分割处理提取出来

doccreateurljsonctoclihtmlscriptgifgptctrappbaidudebugchatgpt2024chat解决方案fix
  • 本文作者:李琛
  • 本文链接: https://wapzz.net/post-16326.html
  • 版权声明:本博客所有文章除特别声明外,均默认采用 CC BY-NC-SA 4.0 许可协议。
本站部分内容来源于网络转载,仅供学习交流使用。如涉及版权问题,请及时联系我们,我们将第一时间处理。
文章很赞!支持一下吧 还没有人为TA充电
为TA充电
还没有人为TA充电
0
  • 支付宝打赏
    支付宝扫一扫
  • 微信打赏
    微信扫一扫
感谢支持
文章很赞!支持一下吧
关于作者
2.3W+
5
0
1
WAP站长官方

快速入门大模型技术与应用,推荐你从Stable Diffusion开始学起

上一篇

chatgpt4和文心一言的简单对比

下一篇
  • 复制图片
按住ctrl可打开默认菜单