您的位置:首页 > 博客中心 > 互联网 >

Requests模块简单使用

时间:2022-05-11 09:34


"""
官网:https://docs.python-requests.org/zh_CN/latest/

Requests 唯一的一个非转基因的 Python HTTP 库,人类可以安全享用。

警告:非专业使用其他 HTTP 库会导致危险的副作用,包括:安全缺陷症、冗余代码症、重新发明轮子症、啃文档症、抑郁、头疼、甚至死亡。
"""
import requests
import json


header_data = {
    "Host": "gank.io",
    "Accept-Encoding": "gzip",
    "User-Agent": "Android-ALI-Moblie 1.3.0",
    "Content-Type": "application/json;charset=UTF-8",
    "Connection": "Keep-Alive"
    }

url = "https://gank.io/api/v2/categories/GanHuo"
res = requests.get(url=url, headers=header_data, params={})

print("status_code:{}".format(res.status_code))
result = res.content
jsonobj = json.loads(result)
print(jsonobj[‘status‘])

res.close()

本类排行

今日推荐

热门手游