1 需求
爬取豆瓣电影动画类别排行榜。
2 代码实现
import json
import requests
url = "https://movie.douban.com/j/chart/top_list"
params = {
'type': '25',
'interval_id': '100:90',
'action': '',
'start': '0',
'limit': '135'
}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0'
}
response = requests.get(url=url, params=params, headers=headers)
content = response.json()
with open('豆瓣电影动画排行榜.txt', 'w', encoding='utf-8') as fp:
for i in content:
title = i['title']
score = i['score']
fp.write(title + " " + score + "\n")