通过python3编写 一个脚本 循环请求下面 连接 通过 page=1 递增方式循环分页 并且打印 返回数据 users数组下的每一个id 并且使用txt保存下来httpsweibocomajaxfriendshipsfriendsrelate=fans&page=1&uid=3977639513&type=fans&newFollowerCount=0请求头通过python3编写 一个脚本 h
以下是Python3代码实现:
import requests
url = 'https://weibo.com/ajax/friendships/friends?relate=fans&page={}&uid=3977639513&type=fans&newFollowerCount=0'
headers = {
'Accept': 'application/json, text/plain, */*',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Client-Version': 'v2.40.50',
'Referer': 'https://weibo.com/u/page/follow/3977639513?relate=fans',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest'
}
with open('ids.txt', 'w', encoding='utf-8') as f:
page = 1
while True:
res = requests.get(url.format(page), headers=headers)
data = res.json().get('data')
users = data.get('users')
if not users:
break
for user in users:
uid = user.get('id')
print(uid)
f.write(str(uid) + '\n')
page += 1
运行后,会循环请求每一页数据,并将其中的每个用户的id打印出来并保存到文件中
原文地址: https://www.cveoy.top/t/topic/e9zy 著作权归作者所有。请勿转载和采集!