第二章 requests模块基础
example4: 爬取豆瓣电影分类排行榜
import requests
if __name__ == "__main__":
url = 'https://movie.douban.com/j/chart/top_list'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36',
}
param = {
'type':'24',
'interval_id':'100:90',
'action':'',
'start':'0',
'limit':'20'
}
response = requests.get(url=url,headers=headers,params=param)
list_data = response.json()
fp = open('./douban.json','w',encoding='utf-8')
json.dump(list_data,fp = fp,ensure_ascii=False)