// ==UserScript== // @name Get Weibo Fans ID // @namespace http://tampermonkey.net/ // @version 1.0 // @description Get Weibo Fans ID by API and save to text file // @author Your name // @match https://weibo.com/* // @grant none // ==/UserScript==

(function() { 'use strict';

// Set loop interval in milliseconds
const LOOP_INTERVAL = 2000;

// Set maximum page number to fetch fans
const MAX_PAGE_NUMBER = 10;

// Set file name to save fans ID
const FILE_NAME = 'weibo-fans-id.txt';

// Get user ID from current URL
const uid = window.location.pathname.match(/\(\d+\)/)[1];

// Create a function to fetch fans data from API
const fetchFansData = (page) => {
    return fetch(`https://weibo.com/ajax/friendships/friends?relate=fans&page=${page}&uid=${uid}&type=fans&newFollowerCount=0`)
        .then(response => response.json())
        .then(data => data.users.map(user => user.id))
        .catch(error => console.error(error));
};

// Create an async function to loop through pages and save fans ID
const loopFetchFansID = async () => {
    let page = 1;
    let fansID = [];
    while (page <= MAX_PAGE_NUMBER) {
        const data = await fetchFansData(page);
        if (data.length === 0) {
            break;
        }
        fansID = fansID.concat(data);
        page++;
        await new Promise(resolve => setTimeout(resolve, LOOP_INTERVAL));
    }
    const blob = new Blob([fansID.join('\n')], { type: 'text/plain' });
    const url = URL.createObjectURL(blob);
    const link = document.createElement('a');
    link.href = url;
    link.download = FILE_NAME;
    link.click();
};

// Execute the function when a button is clicked
const addButton = () => {
    const button = document.createElement('button');
    button.textContent = 'Get Weibo Fans ID';
    button.style.position = 'fixed';
    button.style.bottom = '20px';
    button.style.right = '20px';
    button.style.zIndex = '9999';
    button.onclick = loopFetchFansID;
    document.body.appendChild(button);
};

addButton();

})();

微博粉丝ID提取脚本 - 油猴脚本获取微博粉丝数据

原文地址: https://www.cveoy.top/t/topic/n2zp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录