收藏

micropython wifi联网请求json接口

分类: 基础知识篇 >> ESP32网络相关 发布于 2024-05-16 359次阅读0点赞0收藏
import urequests

import json

import network

#连接WiFi

sta_if = network.WLAN(network.STA_IF)

if not sta_if.isconnected():

    print('connecting to network...')

    sta_if.active(True)

    sta_if.connect('!!wifiname', '!!passwd')

    while not sta_if.isconnected():

        pass

print('network config:', sta_if.ifconfig())

#get请求的头部信息

head = {"User-Agent":'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'}

#B站获取用户信息的URL

url = 'https://api.bilibili.com/x/relation/stat?vmid=!!yourid&jsonp=jsonp'

#获取信息

r = urequests.get(url,headers = head)

#将信息中需要的部分弄出来

datadict = json.loads(r.text)['data']

print('follower is:' + str(datadict['follower']))

print('following is:' + str(datadict['following']))

#以下是具体返回回来的信息

#{"code":0,"message":"0","ttl":1,"data":{"mid":429xxxx,"following":59,"whisper":0,"black":0,"follower":21}}
VIP
购买
建议
意见
联系
客服
在线咨询

您可以与在线客服进行沟通获得帮助

工作日:8:00~22:00节假日:9:00~20:00

微信号: mpyos01

Q Q号: 1401211620

免费
福利
0.038437s