日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

基于python3的一次简单的请求url接口返回json类型结果实例。

發布時間:2025/7/14 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 基于python3的一次简单的请求url接口返回json类型结果实例。 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#-*- coding: UTF-8 -* from urllib import request import json import requests import os #獲取每一頁數據 def get_result_page(url):header = {'Accept-Charset': 'UTF-8','Accept': 'application/json, text/plain, */*','Accept-Encoding': 'gzip, deflate, br','Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2','clientType': 'web','clientVersion': '0.1.0','Cookie': 'JSESSIONID=2032D8E562F3C8A84C72E5FA286541EC','Host': 'web.rr.tv','Origin': 'http://www.rrmj.tv','Referer': 'http://www.rrmj.tv/','User-Agent ': 'Mozilla/5.0 (Windows NT 10.0;WOW64;rv:61.0) Gecko/20100101 Firefox/61.0'}data = Nonerq = request.Request(url, data = data,headers = header)res = request.urlopen(rq);respoen = res.read();result = str(respoen, encoding = "utf-8")return result#根據id下載視頻到本地 def get_video_by_id(id):url ='https://web.rr.tv/v3plus/video/getVideoPlayLinkByVideoId?videoId='+str(id)header = {'Accept-Charset': 'UTF-8','Accept': 'application/json, text/plain, */*','Accept-Encoding': 'gzip, deflate, br','Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2','clientType': 'web','clientVersion': '0.1.0','Cookie': 'JSESSIONID=8804F16A013519D20FE2B3C7DA72BAC4','Host': 'web.rr.tv','Origin': 'http://www.rrmj.tv','Referer': 'http://www.rrmj.tv/','User-Agent ': 'Mozilla/5.0 (Windows NT 10.0;WOW64;rv:61.0) Gecko/20100101 Firefox/61.0'}data = Nonerq = request.Request(url, data = data,headers = header)res = request.urlopen(rq);respoen = res.read();result = str(respoen, encoding = "utf-8")cl = json.loads(result)#print(cl)#print(cl['code'])#print(cl['data']['playLink'])url = cl['data']['playLink']#print(url)r = requests.get(url)with open("C:/Users/Administrator/Desktop/rrsp/"+str(id)+".mp4", "wb") as code:code.write(r.content)#獲取請求結果 def get_data_json():url = 'https://web.rr.tv/v3plus/uper/videoList?userId=10373529&sort=playCount'result = get_result_page(url)js = json.loads(result);res = js['data']['results']print(len(res))for i in res:print(i['id'])result = os.path.exists("C:/Users/Administrator/Desktop/rrsp/"+str(i['id'])+".mp4")#print(result)if result == False:get_video_by_id(i['id'])if __name__ == '__main__':get_data_json() 通過f12找到請求頭

總結

以上是生活随笔為你收集整理的基于python3的一次简单的请求url接口返回json类型结果实例。的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。