萝卜头IT论坛

搜索
查看: 424|回复: 1
收起左侧

Python B站粉丝数+博客状态获取

[复制链接]
发表于 2023-11-4 18:37:17 | 显示全部楼层 |阅读模式
  1. import requests
  2. from bs4 import BeautifulSoup
  3. import datetime
  4. import time
  5. import json
  6. import serial

  7. def get():
  8.      try:
  9.           headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0'}
  10.           response = requests.get('https://api.bilibili.com/x/relation/stat?vmid=' +'1589864343'+ '&jsonp=jsonp',headers=headers)
  11. #用你的B站ID替换我的ID(1589864343)

  12.           J_data = json.loads(response.text)
  13.           data = (J_data['data']['follower'])
  14.           return data
  15.       except:
  16.           time.sleep(3)

  17. def status(url):
  18.      try:
  19.          response = requests.get(url)
  20.          if response.status_code == 200:
  21.              return True
  22.          else:
  23.              return False
  24.     except requests.exceptions.RequestException:
  25.         return False

  26. while True:
  27.     try:
  28.                   data = get()
  29.                   status = status("https://ink.cpolar.cn")
  30. #用你的博客地址替换我的博客地址(https://ink.cpolar.cn)
  31.                   if status == True:
  32.                            status = "Online"
  33.                   else:
  34.                            status = "Offline"
  35.         print("粉丝数:",data,"博客状态:",status)
  36.                 time.sleep(60)
  37.     except:
  38.                 time.sleep(1)
复制代码
此代码可实时获取B站粉丝数量和你的博客访问状态
用树莓派和一块小屏幕即可实现:
1AE2C8A5B476C051957C6F5BFB070E44 大.jpeg
F2018B18A0A6287A2F0E194F1D96F018.jpg
另外欢迎关注我的B站账号:https://space.bilibili.com/1589864343


回复

使用道具 举报

发表于 2023-11-4 21:02:46 | 显示全部楼层
是爬虫吗,感觉好高级
回复

使用道具 举报

联系我们(Contact)|手机版|萝卜头IT论坛 ( 苏ICP备15050961号-1 )

GMT+8, 2024-4-28 20:43 , Processed in 0.098296 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表