Written by Anonymous
function delay (time) {
return new Promise(r => {
setTimeout(() => r(), time || 1000);
});
}
const baseUrl = 'https://m.weibo.cn/api/container/getIndex?containerid=231093_-_selffollowed';
async function runTask (taskUrl) {
const allRecord = [];
let end = false;
for (let page = 1; ; page++) {
try {
let d = await fetch(`${taskUrl}&page=${page}`, {credentials: "same-origin"})
.then(r => r.json())
.then(d => {
let c = d.data.cards;
if (!c.length) {
end = true;
return;
}
const all = c[c.length-1].card_group.map(i => ({
userId: i.user.id,
userName: i.user.screen_name
})
);
allRecord.push(...all);
});
} catch (e) {
continue;
}
if (end) {
break;
}
await delay();
}
console.log(allRecord);
// console.log(JSON.stringify(allRecord));
};
(async function () {
await runTask(baseUrl);
})();