ToB企服应用市场:ToB评测及商务社交产业平台

标题: 一键批量导出本身企鹅挚友 [打印本页]

作者: 用多少眼泪才能让你相信    时间: 2024-9-22 19:14
标题: 一键批量导出本身企鹅挚友
先附上原作者的代码
  1. /**
  2.      * @author ius.
  3.      * @date 2022/8/1
  4.      * @introduction 获取QQ好友列表
  5.      */
  6.     function getCookie(aim) {
  7.         const allText = document.cookie.replace(/\s*/g, ''); //document.cookie
  8.         oneText = allText.split(";");
  9.         for (var two of oneText) {
  10.             const three = two.split("=");
  11.             if (aim === three[0]) {
  12.                 return two;
  13.             }
  14.         }
  15.     }
  16.     const gtk = user.getToken();
  17.     const uin = getCookie("uin").substring(5);
  18.     const xhr = new XMLHttpRequest();
  19.     const qzonetoken = window.shine0callback;
  20.     var url = 'https://mobile.qzone.qq.com/friend/mfriend_list?qzonetoken=' + qzonetoken + '&g_tk=' + gtk + '&res_uin=' + uin + '&res_type=normal&format=json&count_per_page=10&page_index=0&page_type=0&mayknowuin=&qqmailstat=';
  21.     xhr.onreadystatechange = function () {
  22.         if (this.readyState == 4 && this.status == 200) {
  23.             const json = JSON.parse(xhr.responseText)
  24.             const allGroup = json.data.gpnames;
  25.             const allFriend = json.data.list;
  26.             var consoleContext = "";
  27.             for (var groupid of allGroup) {
  28.                 consoleContext += groupid["gpname"] + ":\n";
  29.                 for (const friendid of allFriend) {
  30.                     if (groupid["gpid"] === friendid["groupid"]) {
  31.                         consoleContext += "  " + friendid["remark"] + "(" + friendid["uin"] + ")" + "\n";
  32.                     }
  33.                 }
  34.             }
  35.             console.log(consoleContext);
  36.         }
  37.     }
  38.     xhr.open('GET', url)
  39.     xhr.withCredentials = true;
  40.     xhr.send()
复制代码
获取的信息是挚友名字+(账号)
下面是我改良版本
获取的信息是账号
  1. // 获取指定名称的cookie值
  2. function getCookie(aim) {
  3.     // 去除cookie字符串中的空格
  4.     const allText = document.cookie.replace(/\s*/g, '');
  5.     // 将cookie字符串按分号分割成数组
  6.     const oneText = allText.split(";");
  7.    
  8.     // 遍历每个cookie
  9.     for (var two of oneText) {
  10.         // 将cookie按等号分割成键值对
  11.         const three = two.split("=");
  12.         // 检查当前cookie的名称是否与目标名称匹配
  13.         if (aim === three[0]) {
  14.             return two; // 返回匹配的cookie
  15.         }
  16.     }
  17. }
  18. // 获取用户的GTK(用于验证的令牌)
  19. const gtk = user.getToken();
  20. // 从cookie中获取用户的uin,并去掉前缀
  21. const uin = getCookie("uin").substring(5);
  22. // 创建一个XMLHttpRequest对象以发送HTTP请求
  23. const xhr = new XMLHttpRequest();
  24. // 获取qzonetoken
  25. const qzonetoken = window.shine0callback;
  26. // 构建请求的URL
  27. var url = 'https://mobile.qzone.qq.com/friend/mfriend_list?qzonetoken=' + qzonetoken + '&g_tk=' + gtk + '&res_uin=' + uin + '&res_type=normal&format=json&count_per_page=10&page_index=0&page_type=0&mayknowuin=&qqmailstat=';
  28. // 设置请求状态变化的回调函数
  29. xhr.onreadystatechange = function () {
  30.     // 当请求完成且响应状态为200(成功)时
  31.     if (this.readyState == 4 && this.status == 200) {
  32.         // 解析JSON格式的响应文本
  33.         const json = JSON.parse(xhr.responseText);
  34.         // 获取所有分组
  35.         const allGroup = json.data.gpnames;
  36.         // 获取所有好友列表
  37.         const allFriend = json.data.list;
  38.         // 遍历每个分组
  39.         for (var groupid of allGroup) {
  40.             // 遍历每个好友
  41.             for (const friendid of allFriend) {
  42.                 // 检查好友的分组ID是否与当前分组的ID匹配
  43.                 if (groupid["gpid"] === friendid["groupid"]) {
  44.                     // 如果匹配,打印该好友的uin(账号),每个账号单独一行
  45.                     console.log(friendid["uin"]);
  46.                 }
  47.             }
  48.         }
  49.     }
  50. }
  51. // 初始化GET请求
  52. xhr.open('GET', url);
  53. // 允许携带凭证(如cookie)
  54. xhr.withCredentials = true;
  55. // 发送请求
  56. xhr.send();
复制代码
使用方式
电脑EDGE或者Chrome浏览器
打开QQ空间登录然后切换仿真模式
然后在把地址改为:https://h5.qzone.qq.com/mqzone/index
最后把代码放在控制台上回车就搞定了
下面以edge浏览器为例子


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4