#本文仅供学习交流之用
import json
import requests
import pandas as pdheaders = {'Accept': 'application/json, text/plain, */*','Accept-Language': 'zh-CN,zh;q=0.9','Cache-Control': 'no-cache','Connection': 'keep-alive','Content-Type': 'application/x-www-form-urlencoded','Origin': 'https://ys.endata.cn','Pragma': 'no-cache','Referer': 'https://ys.endata.cn/BoxOffice/Ranking','Sec-Fetch-Dest': 'empty','Sec-Fetch-Mode': 'cors','Sec-Fetch-Site': 'same-origin','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36','sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"','sec-ch-ua-mobile': '?0','sec-ch-ua-platform': '"Windows"',
}
top=input("请你输入我查询电影票房的数目:")
data = {'r': '0.02282167524158729','top': top,'type': '0',
}response = requests.post('https://ys.endata.cn/enlib-api/api/home/getrank_mainland.do',cookies=cookies,headers=headers,data=data,
)
# print(response.text)
context = json.loads(response.text)
list = []
for movie_data in context['data']['table0']:print(movie_data)dic = {}dic['MovieName']= movie_data['MovieName']dic['ReleaseTime']= movie_data['ReleaseTime']dic["BoxOffice"]= movie_data['BoxOffice']list.append(dic)df=pd.DataFrame(list)df.to_csv("票房.csv")df.to_excel("票房.xlsx",index=False)# print(MovieName)