本版
查看: 4772|回复: 1

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

[复制链接]

[Lv.7]特大萝卜

You're the {css} to my html.

楼主(1#)
发表于 2023-11-4 18:37:17 | 只看该作者 |只看大图 |倒序浏览 |阅读模式
  1. import requests
    from 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


Ace_qingfeng
Qingfeng_129
回复

支持 | 反对  0 支持 / 0 反对 评分 举报

[Lv.8]超级萝卜

沙发(2#)
发表于 2023-11-4 21:02:46 | 只看该作者
是爬虫吗,感觉好高级

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

GMT+8, 2026-10-22 02:21 , Processed in 0.07 second(s), 20 queries , Gzip On.

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