获取A 账号关注列表
- 前往微博 H5 版首页 (
https://m.weibo.cn)
- 登录 A 账号
- 右键 “检查” 打开开发者工具(F12快捷键),复制下面的代码,粘贴到控制台,等待结果并复制
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# 第一种方式
(() => {
let uid = config.uid, follows = []
const pageQuery = (page = 1) => {
let xhr = new XMLHttpRequest()
xhr.onreadystatechange = () => {
if(xhr.readyState == 4 && xhr.status == 200){
let data = JSON.parse(xhr.responseText).data
if(data.msg == '这里还没有内容') return console.log(JSON.stringify(follows))
data.cards.forEach(card => follows.push(card.user.id))
pageQuery(page + 1)
}
}
xhr.open('GET', `/api/container/getSecond?luicode=10000011&lfid=100505${uid}&uid=${uid}&containerid=100505${uid}_-_FOLLOWERS&page=${page}`)
xhr.send()
}
pageQuery()
})();
# 第二种方式
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);
})();
|
稍等片刻获取JSON数据格式
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
{
card_type: 10,
user: {
id: 0,
screen_name: "xxxxxxxxxx",
profile_image_url: "https://tvax4.sinaimg.cn/crop.0.0.664.664.180/5487abcdly8g0clh7uhdkj20ig0ihjsr.jpg?KID=imgbed,tva&Expires=1571513714&ssig=xHcSHWmQ4a",
profile_url: "https://m.weibo.cn/u/xxxxxxxxxx?uid=v&luicode=10000012&lfid=1005052118906250_-_FOLLOWERS",
statuses_count: 7293,
verified: true,
verified_type: 0,
verified_type_ext: 1,
verified_reason: "xxxx",
close_blue_v: false,
description: "xxxxx",
gender: "m",
mbtype: 12,
urank: 39,
mbrank: 6,
follow_me: false,
following: true,
followers_count: 1125699,
follow_count: 489,
cover_image_phone: "https://tva1.sinaimg.cn/crop.0.0.640.640.640/xxxxxx.jpg",
avatar_hd: "https://wx4.sinaimg.cn/orj480/xxxxxx.jpg",
like: false,
like_me: false,
desc1: null,
desc2: null
},
scheme: "https://m.weibo.cn/u/1418177485?uid=1418177485&luicode=xxxxxxx",
desc1: "xxxxxx",
desc2: ""
}
|
比如我要筛选关注数和为关注我的人,只需要修改 data.cards.forEach(card => follows.push(card.user.id)) 这句,我修改如下,就是指定了这个人不关注我
1
2
3
|
if(card.user.follow_me == false){
follows.push(card.user.id)
}
|
为 B 账号添加关注
- 前往 PC 版首页 (
www.weibo.com)
- 退出 A 账号,登录 B 账号
- 右键 “检查” 打开开发者工具,复制下面的代码并填入上一步得到的列表,粘贴到控制台,等待全部关注完成
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
(list => {
let index = -1, length = list.length
const follow = uid => {
let xhr = new XMLHttpRequest()
xhr.onreadystatechange = () => {
if(xhr.readyState == 4 && xhr.status == 200){
let data = JSON.parse(xhr.responseText)
if(data.code == 100000)
console.log(`${index + 1}/${length}`, uid, data.data.fnick, '关注成功')
else if(data.code == 100001)
console.log(`${index + 1}/${length}`, uid, '关注失败')
}
}
xhr.open('POST', `/aj/f/followed?ajwvr=6&__rnd=${Date.now()}`)
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
xhr.send(`uid=${uid}&objectid=&f=1&extra=&refer_sort=&refer_flag=1005050001_&location=page_100505_home&oid=${uid}&wforce=1&nogroup=false&fnick=&refer_lflag=&refer_from=profile_headerv6&_t=0`)
}
let scheduled = setInterval(() => {
index += 1
follow(list[index])
}, 2000)
setTimeout(() => {
clearTimeout(scheduled)
}, 2000 * length)
})(/*上一步的结果*/)
|
每天一个id最多关注200人,超过会关注失败。
Reference:https://github.com/nondanee/weiboBatchFollow