import requests
import json
import jsonpath
import UAS
class Douban:
def __init__(self):
self.url='https://movie.douban.com/j/chart/top_list?type=24&interval_id=100%3A90&action=&start=0&limit=20'
self.headers=UAS.headers
@property
def acquire_request(self):
response=requests.get(self.url,headers=self.headers)
json_data=response.json()
# with open('douban.json','w')as f:
# json.dump(json_data,f)
return json_data
def firm_grade(self):
firm_grade_name = jsonpath.jsonpath(self.acquire_request, '$.[*].title')
grade=jsonpath.jsonpath(self.acquire_request,'$.[*].rating.[0]')
# print(f'电影名为:{firm_grade_name}')
# print(f'评分为:{grade}')
firm_grade=dict(zip(firm_grade_name,grade))
print(firm_grade)
firm_name=Douban()
firm_name.firm_grade()
总是报错