Go:简单的bilibiliApi请求

本文介绍如何利用Go语言进行bilibili API请求,通过编写`test.go`和`main.go`文件,实现对JSON数据的处理,从而获取并解析B站的相关信息。内容涉及Golang的基础语法和HTTP请求库的应用。
摘要由CSDN通过智能技术生成

test.go

package test

import (
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"net/http"
	"os"
)

type InfoRequest struct {
	Bvids []string
}

type ViewInfo struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    struct {
		Bvid  string `json:"bvid"`
		Title string `json:"title"`
		Desc  string `json:"desc"`
	} `json:"data"`
}

type InfoReponse struct {
	Infos []ViewInfo
}

var Logger *log.Logger

const BILIBILI_API = "http://api.bilibili.com/x/web-interface/view?"

func init() {
	file, err := os.OpenFile("test.txt", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0644)
	if err != nil {
		panic(err)
	}
	Logger = log.New(io.MultiWriter(os.Stdout, file), "THELog: ", log.LstdFlags)
}

func GetBVInfo(requestBV In
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值