豆瓣电视剧JSON爬虫

import requests
import json
# 'https://movie.douban.com/tv/#!type=tv&tag=%E7%83%AD%E9%97%A8&sort=recommend&page_limit=20&page_start=0'
url = 'https://movie.douban.com/j/search_subjects?type=tv&tag=%E7%83%AD%E9%97%A8&sort=recommend&page_limit=20&page_start=0'
# url = 'https://movie.douban.com/j/search_subjects?type=tv&tag=%E7%83%AD%E9%97%A8&sort=recommend&page_limit=200&page_start=1'
headers = {
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'}
resp = requests.get(url, headers)
# 把响应数据转成str类型
data = resp.content.decode()
# 把电视数据转成字典
dict_data = json.loads(data)
print(dict_data)
result_list = dict_data['subjects']
data_list = []
for result in result_list:
    temp = {}
    temp['title'] = result['title']
    temp['rate'] = result['rate']
    temp['url'] = result['url']
    data_list.append(temp)
print(data_list)

f = open('data.json','w',encoding='utf8')
json.dump(data_list,f,ensure_ascii=False)


你可能感兴趣的:(豆瓣电视剧JSON爬虫)