import requests,json,random,re
from fake_useragent import UserAgent
ua = UserAgent()
url = 'https://movie.douban.com/j/chart/top_list?type=11&interval_id=100%3A90&action=&start=0&limit=10'
headers = {'User-Agent':ua.random}
# response = requests.get(url,headers=headers).json()
response = requests.get(url,headers=headers).text
# lis = []
# for i in response:
# dic = {}
# title = i['title']
# actors = i['actors']
# cover_url = i['cover_url']
# dic['title']=title
# dic['actors']=actors
# dic['url']=cover_url
# lis.append(dic)
# with open('douban.json','w',encoding='utf-8') as f:
# json.dump(lis,f,ensure_ascii=False)
# with open('douban1.json', 'w', encoding='utf-8') as f:
# json.dump(response, f, ensure_ascii=False)
pattern = re.compile(r'{.*?}')
pattern_list = pattern.findall(response)
# print(pattern_list)
for i in pattern_list:
actors = re.compile(r'"actors":\[(.*?)\]')
actors_list = actors.findall(i)
# print(actors_list)
id = re.compile(r'"\w\w":".*?"')
id_list = id.findall(i)
print(id_list)