Python-get请求
案例一:
# coding=utf-8 ''' 历史上的今天AppKey:key 接口文档地址 https://www.juhe.cn/docs/api/id/63 接口地址:http://v.juhe.cn/todayOnhistory/queryEvent.php 返回格式:json 请求方式:get 请求示例:http://v.juhe.cn/todayOnhistory/queryEvent.php?key=YOURKEY&date=1/1 接口备注:根据日期查询事件 ''' import requests import datetime time = datetime.datetime.now().timetuple() data_time = str(time.tm_mon) + "/" + str(time.tm_mday) key = "key" def Query_Event(): url = "http://v.juhe.cn/todayOnhistory/queryEvent.php" params = { "key":key, "date":data_time } res = requests.get(url,params=params) print(res.url) print(res.request) print(res.headers) print(res.json()) return res.text print(Query_Event())

案例二:
# coding=utf-8 ''' 星座 AppKey:key 接口文档地址 https://www.juhe.cn/docs/api/id/58 接口地址:http://web.juhe.cn:8080/constellation/getAll 返回格式:json 请求方式:http get 请求示例:http://web.juhe.cn:8080/constellation/getAll?consName=%E7%8B%AE%E5%AD%90%E5%BA%A7&type=today&key=申请的KEY ''' import requests types = ["today","tomorrow","week","month","year"] key = "key" consName = "双鱼座" url = "http://web.juhe.cn:8080/constellation/getAll" for type in types: params = { "type": type, "key": key, "consName": consName } res = requests.get(url, params=params) print(res.url,res.text,res.json(),res.history)

案例三:
# coding=utf-8 ''' 笑话大全 AppKey:key 接口文档地址 https://www.juhe.cn/docs/api/id/95 接口地址:http://v.juhe.cn/joke/content/list.php 返回格式:json 请求方式:http get 请求示例:http://v.juhe.cn/joke/content/list.php?key=您申请的KEY&page=2&pagesize=10&sort=asc&time=1418745237 接口备注:根据时间戳返回该时间点前或后的笑话列表 ''' import requests import time key = "key" time = time.time() def Content_List(time): url = "http://v.juhe.cn/joke/content/list.php" params = { "sort":"desc", "page":1, "pagesize":10, "time":time, "key":key } res = requests.get(url,params=params) return res.url,res.text,res.json() if __name__ == "__main__": print(Content_List(int(time)))

案例四:
# coding=utf-8 ''' 周公解梦 https://www.juhe.cn/docs/api/id/64 AppKey:key 接口地址:http://v.juhe.cn/dream/category 返回格式:json/xml 请求方式:http get 请求示例:http://v.juhe.cn/dream/category?key=您申请的key 接口备注:梦境类型 ''' import requests class ZhouGongJieMeng(object): def __init__(self): self.key = "key" self.url = "http://v.juhe.cn/dream/category" def Category(self): url = self.url params = { "key":self.key } res = requests.get(url,params=params) return res.text if __name__ == "__main__": zg = ZhouGongJieMeng() print(zg.Category())

# coding=utf-8
'''
笑话大全
AppKey:61453cf60a746632636b89647c779d32
接口文档地址
https://www.juhe.cn/docs/api/id/95
接口地址:http://v.juhe.cn/joke/content/list.php
返回格式:json
请求方式:http get
请求示例:http://v.juhe.cn/joke/content/list.php?key=您申请的KEY&page=2&pagesize=10&sort=asc&time=1418745237
接口备注:根据时间戳返回该时间点前或后的笑话列表
'''
import requests
import time
key = "61453cf60a746632636b89647c779d32"
time = time.time()
def Content_List(time):
url = "http://v.juhe.cn/joke/content/list.php"
params = {
"sort":"desc",
"page":1,
"pagesize":10,
"time":time,
"key":key
}
res = requests.get(url,params=params)
return res.url,res.text,res.json()
if __name__ == "__main__":
print(Content_List(int(time)))

浙公网安备 33010602011771号