吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4472|回复: 56
上一主题 下一主题
收起左侧

[其他原创] 【油猴脚本】抖音用户主页数据下载

  [复制链接]
跳转到指定楼层
楼主
xxmdmst 发表于 2023-7-28 11:03 回帖奖励
脚本安装链接:https://greasyfork.org/zh-CN/scripts/471880-%E6%8A%96%E9%9F%B3%E7%94%A8%E6%88%B7%E4%B8%BB%E9%A1%B5%E6%95%B0%E6%8D%AE%E4%B8%8B%E8%BD%BD
安装插件后,打开任意抖音用户主页右上角会出现如下两个按钮:


点击下载可以得到如下格式的文件:

里面包含原始视频链接,可以自由选择是否手动下载视频。

源码如下:
(function () {
    'use strict';
    let aweme_list = [];
    let userKey = [
        "昵称", "关注", "粉丝",
        "获赞", "抖音号", "IP属地",
        "年龄", "签名", "作品数", "主页"
    ];
    let userData = [];

    function extractDataFromScript() {
        const scriptTag = document.getElementById('RENDER_DATA');
        if (!scriptTag) return;
        let data = JSON.parse(decodeURIComponent(scriptTag.innerHTML));

        for (const prop in data) {
            if (data.hasOwnProperty(prop) && prop !== "_location" && prop !== "app") {
                const user = data[prop];
                let userInfo = user.user.user;
                console.log(userInfo);
                userData.push(
                    userInfo.nickname, userInfo.followingCount, userInfo.mplatformFollowersCount,
                    userInfo.totalFavorited, userInfo.uniqueId, userInfo.ipLocation,
                    userInfo.age, '"' + userInfo.desc + '"', userInfo.awemeCount, "https://www.douyin.com/user/" + userInfo.secUid
                );
                let post_data = user.post.data.map(item => Object.assign({"desc": item.desc}, item.stats,
                    {"url": "https:" + item.video.playAddr[0].src}));
                aweme_list = aweme_list.concat(post_data);
            }
        }
    }

    function createButton(title, top) {
        top = top === undefined ? "60px" : top;
        const button = document.createElement('button');
        button.textContent = title;
        button.style.position = 'fixed';
        button.style.right = '5px';
        button.style.top = top;
        button.style.zIndex = '90000';
        document.body.appendChild(button);
        return button
    }

    function txt2file(txt, filename) {
        const blob = new Blob([txt], {type: 'text/plain'});
        const url = URL.createObjectURL(blob);
        const link = document.createElement('a');
        link.href = url;
        link.download = filename.replace(/[\/:*?"<>|]/g, "");
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
        URL.revokeObjectURL(url);
    }

    function downloadData() {
        let text = userKey.join(",") + "\n" + userData.join(",") + "\n\n";
        text += "作品描述,点赞数,评论数,收藏数,分享数,下载链接\n";
        aweme_list.forEach(item => {
            text += ['"' + item.desc + '"', item.diggCount, item.commentCount,
                item.collectCount, item.shareCount, item.url].join(",") + "\n"
        });
        txt2file(text, userData[0] + ".csv");
    }

    function interceptResponse() {
        const originalSend = XMLHttpRequest.prototype.send;
        XMLHttpRequest.prototype.send = function () {
            const self = this;
            this.onreadystatechange = function () {
                if (self.readyState === 4) {
                    if (self._url.indexOf("/aweme/v1/web/aweme/post") > -1) {
                        var json = JSON.parse(self.response);
                        console.log(json.aweme_list);
                        let post_data = json.aweme_list.map(item => Object.assign(
                            {"desc": item.desc},
                            {
                                "diggCount": item.statistics.digg_count,
                                "commentCount": item.statistics.comment_count,
                                "collectCount": item.statistics.collect_count,
                                "shareCount": item.statistics.share_count,
                            },
                            {"url": item.video.play_addr.url_list[0]}));
                        aweme_list = aweme_list.concat(post_data);
                    }
                }
            };
            originalSend.apply(this, arguments);
        };
    }

    function scrollPageToBottom() {
        const SCROLL_DELAY = 1000; // Adjust the delay between each scroll action (in milliseconds)
        let scrollInterval;

        function getScrollPosition() {
            return scrollY || pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
        }

        function scrollToBottom() {
            scrollTo(0, document.body.scrollHeight);
        }

        function hasReachedBottom() {
            return getScrollPosition() >= (document.body.scrollHeight - innerHeight);
        }

        function scrollLoop() {
            if (!hasReachedBottom()) {
                scrollToBottom();
            } else {
                console.log("Reached the bottom of the page!");
                clearInterval(scrollInterval);
            }
        }

        function startScrolling() {
            scrollInterval = setInterval(scrollLoop, SCROLL_DELAY);
        }

        let button = createButton('开启自动下拉到底', '60px');
        button.addEventListener('click', startScrolling);
    }

    // To start scrolling, call the function:
    scrollPageToBottom();
    interceptResponse();
    window.onload = () => {
        extractDataFromScript();
        let button = createButton("下载已加载数据", "81px");
        button.addEventListener('click', downloadData);
    };

})();


后面计划再开发crx插件版本,但是目前测试插件中无法触发xhr方法,只能获取到初始数据,还在研究中...

免费评分

参与人数 15吾爱币 +19 热心值 +13 收起 理由
wyhzxcwyh + 1 + 1 谢谢@Thanks!
bokuu + 1 + 1 谢谢@Thanks!
87yangleduo + 1 + 1 我很赞同!
yangyan6011795 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
zhiyuan88890 + 1 + 1 我很赞同!
jamessteed + 1 + 1 谢谢@Thanks!
Guangnianyinan + 1 + 1 我很赞同!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
shenlang78 + 1 + 1 我很赞同!
yanglinman + 1 谢谢@Thanks!
n123456J + 1 用心讨论,共获提升!
bookbug + 1 我很赞同!
hedun + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
云藏龍曦 + 1 我很赞同!
hljyslyj + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

推荐
 楼主| xxmdmst 发表于 2023-7-28 11:12 |楼主
关键代码之一:
[JavaScript] 纯文本查看 复制代码
    function extractDataFromScript() {
        const scriptTag = document.getElementById('RENDER_DATA');
        if (!scriptTag) return;
        let data = JSON.parse(decodeURIComponent(scriptTag.innerHTML));
 
        for (const prop in data) {
            if (data.hasOwnProperty(prop) && prop !== "_location" && prop !== "app") {
                const user = data[prop];
                let userInfo = user.user.user;
                userData.push(
                    userInfo.nickname, userInfo.followingCount, userInfo.mplatformFollowersCount,
                    userInfo.totalFavorited, userInfo.uniqueId, userInfo.ipLocation,
                    userInfo.age, '"' + userInfo.desc + '"', userInfo.awemeCount, "https://www.douyin.com/user/" + userInfo.secUid
                );
                let post_data = user.post.data.map(item => Object.assign({"desc": item.desc}, item.stats,
                    {"url": "https:" + item.video.playAddr[0].src}));
                aweme_list = aweme_list.concat(post_data);
            }
        }
    }
3#
zxh188300047 发表于 2023-7-28 12:34
4#
VGT-dy 发表于 2023-7-28 12:39
5#
RYJK 发表于 2023-7-28 12:40
有去水印下载不的
6#
qtqydyuy 发表于 2023-7-28 12:44
保存了待用,谢谢分享
7#
salend 发表于 2023-7-28 12:46
这个得赞了 牛
8#
izhuol 发表于 2023-7-28 12:55
学习学习
9#
xu688 发表于 2023-7-28 13:43
终于不用一个一个点着下了,感谢楼主分享爱
10#
CloudLove 发表于 2023-7-28 14:05
感谢楼主,这下方便了很多
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-11 19:10

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表