一键批量导出自己企鹅好友

先附上原作者的代码

复制代码
/**
     * @author ius.
     * @date 2022/8/1
     * @introduction 获取QQ好友列表
     */
    function getCookie(aim) {
        const allText = document.cookie.replace(/\s*/g, ''); //document.cookie
        oneText = allText.split(";");
        for (var two of oneText) {
            const three = two.split("=");
            if (aim === three[0]) {
                return two;
            }
        }
    }

    const gtk = user.getToken();
    const uin = getCookie("uin").substring(5);
    const xhr = new XMLHttpRequest();
    const qzonetoken = window.shine0callback;
    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=';
    xhr.onreadystatechange = function () {
        if (this.readyState == 4 && this.status == 200) {
            const json = JSON.parse(xhr.responseText)
            const allGroup = json.data.gpnames;
            const allFriend = json.data.list;
            var consoleContext = "";
            for (var groupid of allGroup) {
                consoleContext += groupid["gpname"] + ":\n";
                for (const friendid of allFriend) {
                    if (groupid["gpid"] === friendid["groupid"]) {
                        consoleContext += "  " + friendid["remark"] + "(" + friendid["uin"] + ")" + "\n";
                    }
                }
            }
            console.log(consoleContext);
        }
    }
    xhr.open('GET', url)
    xhr.withCredentials = true;
    xhr.send()

获取的信息是好友名字+(账号)

下面是我改良版本

获取的信息是账号

复制代码
// 获取指定名称的cookie值
function getCookie(aim) {
    // 去除cookie字符串中的空格
    const allText = document.cookie.replace(/\s*/g, '');
    // 将cookie字符串按分号分割成数组
    const oneText = allText.split(";");
    
    // 遍历每个cookie
    for (var two of oneText) {
        // 将cookie按等号分割成键值对
        const three = two.split("=");
        // 检查当前cookie的名称是否与目标名称匹配
        if (aim === three[0]) {
            return two; // 返回匹配的cookie
        }
    }
}

// 获取用户的GTK(用于验证的令牌)
const gtk = user.getToken();
// 从cookie中获取用户的uin,并去掉前缀
const uin = getCookie("uin").substring(5);

// 创建一个XMLHttpRequest对象以发送HTTP请求
const xhr = new XMLHttpRequest();
// 获取qzonetoken
const qzonetoken = window.shine0callback;

// 构建请求的URL
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=';

// 设置请求状态变化的回调函数
xhr.onreadystatechange = function () {
    // 当请求完成且响应状态为200(成功)时
    if (this.readyState == 4 && this.status == 200) {
        // 解析JSON格式的响应文本
        const json = JSON.parse(xhr.responseText);
        // 获取所有分组
        const allGroup = json.data.gpnames;
        // 获取所有好友列表
        const allFriend = json.data.list;

        // 遍历每个分组
        for (var groupid of allGroup) {
            // 遍历每个好友
            for (const friendid of allFriend) {
                // 检查好友的分组ID是否与当前分组的ID匹配
                if (groupid["gpid"] === friendid["groupid"]) {
                    // 如果匹配,打印该好友的uin(账号),每个账号单独一行
                    console.log(friendid["uin"]);
                }
            }
        }
    }
}

// 初始化GET请求
xhr.open('GET', url);
// 允许携带凭证(如cookie)
xhr.withCredentials = true;
// 发送请求
xhr.send();

使用方式

电脑EDGE或者Chrome浏览器

打开QQ空间登录然后切换仿真模式

然后在把地址改为:https://h5.qzone.qq.com/mqzone/index

最后把代码放在控制台上回车就搞定了

下面以edge浏览器为例子

相关推荐
爱写代码的小朋友1 天前
从“工具使用者”到“思维启蒙者”:高中信息技术教师计算机知识体系的重构
教学·计算机知识·信息技术教师
爱笑的源码基地2 天前
小微企业ERP源码,采用SpringBoot+Vue+ElementUI+UniAPP技术架构,支持二次开发及商用授权
java·源码·二次开发·erp·源代码·mrp生产计划
不简说3 天前
前端可视化打印设计器sv-print,一口气更新了30版
前端·源码·产品
坐吃山猪3 天前
【Nanobot】README04_LEVEL2 提供商系统设计
python·源码·agent·nanobot
坐吃山猪3 天前
【Nanobot】README09_LEVEL4 添加新聊天渠道
开发语言·网络·python·源码·nanobot
坐吃山猪3 天前
【Nanobot】README03_LEVEL2_工具系统架构
python·源码·agent·nanobot
深入云栈5 天前
第一篇:Nacos 2.x 架构全览——为什么从HTTP转向gRPC?
源码
爱笑的源码基地6 天前
拿来即用:基于Spring Cloud+UniApp的智慧工地源码,架构清晰易扩展
java·云计算·源码·智慧工地·程序·开箱即用·数字工地
冬奇Lab6 天前
RAG 系列(十七):Agentic RAG——让 Agent 主导检索过程
人工智能·llm·源码
谙弆悕博士6 天前
【附C++源码】从零开始实现 2048 游戏
java·c++·游戏·源码·项目实战·2048