请用Python写出一个爬取微博用户“邓超”关注列表的程序代码
时间: 2023-03-14 09:12:46 浏览: 90
import requests
import json# 获取access_token
url = 'https://api.weibo.com/oauth2/access_token'
payload = {'client_id': 'your_client_id',
'client_secret': 'your_client_secret',
'grant_type': 'client_credentials'}
r = requests.post(url, data=payload)
result = json.loads(r.text)
access_token = result.get('access_token')# 获取邓超的uid
url = 'https://api.weibo.com/2/users/show.json'
payload = {'access_token': access_token,
'screen_name': '邓超'}
r = requests.get(url, params=payload)
result = json.loads(r.text)
uid = result.get('id')# 获取邓超的关注列表
url = 'https://api.weibo.com/2/friendships/friends/bilateral.json'
payload = {'access_token': access_token,
'uid': uid}
r = requests.get(url, params=payload)
result = json.loads(r.text)
follow_list = result.get('users')# 打印出关注列表
for follow in follow_list:
print(follow.get('screen_name'))
阅读全文