用python爬取B站用户信息
用python爬取B站用户信息话不多说,直接上代码!import requestsdef get_star(url):html = requests.get(url).json()['data']follower = html['follower']following = html['following']print("粉丝数:{},关注数:{}".format(follower,followin
·
用python爬取B站用户信息
话不多说,直接上代码!
import requests
def get_star(url):
html = requests.get(url).json()['data']
follower = html['follower']
following = html['following']
print("粉丝数:{},关注数:{}".format(follower,following))
print("-"*20)
def download_face(face_url,name):
image = requests.get(face_url).content
with open("C:/Users/86135/Desktop/{}.jpg".format(name),'wb') as f:
f.write(image)
def get_userdata(url):
jsondata = requests.get(url).json()['data']
name = jsondata['name']
sex = jsondata['sex']
level = jsondata['level']
birthday = jsondata['birthday']
coins = jsondata['coins']
print("名字是:{} 性别是:{} 等级是:{} 生日是:{} 硬币数目:{}".format(name,sex,level,birthday,coins))
face_url = jsondata['face']
print("正在下载头像……")
download_face(face_url,name)
def main():
for i in range(1, 11):
url = "https://api.bilibili.com/x/space/acc/info?mid={}&jsonp=jsonp".format(i)
get_userdata(url)
url2 = "https://api.bilibili.com/x/relation/stat?vmid={}&jsonp=jsonp".format(i)
get_star(url2)
if __name__ == '__main__':
main()
运行结果如下:
更多推荐
所有评论(0)