Python B站粉丝数+博客状态获取
import requestsfrom bs4 import BeautifulSoup
import datetime
import time
import json
import serial
def get():
try:
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0'}
response = requests.get('https://api.bilibili.com/x/relation/stat?vmid=' +'1589864343'+ '&jsonp=jsonp',headers=headers)
#用你的B站ID替换我的ID(1589864343)
J_data = json.loads(response.text)
data = (J_data['data']['follower'])
return data
except:
time.sleep(3)
def status(url):
try:
response = requests.get(url)
if response.status_code == 200:
return True
else:
return False
except requests.exceptions.RequestException:
return False
while True:
try:
data = get()
status = status("https://ink.cpolar.cn")
#用你的博客地址替换我的博客地址(https://ink.cpolar.cn)
if status == True:
status = "Online"
else:
status = "Offline"
print("粉丝数:",data,"博客状态:",status)
time.sleep(60)
except:
time.sleep(1)此代码可实时获取B站粉丝数量和你的博客访问状态
用树莓派和一块小屏幕即可实现:
另外欢迎关注我的B站账号:https://space.bilibili.com/1589864343
是爬虫吗,感觉好高级
页:
[1]