代码
import requests
import json
if __name__ == "__main__":
url = 'https://movie.douban.com/j/chart/top_list'
#post请求参数处理(同get请求一致)
headers = {
"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
}
param = {
'type':'24',
'interval_id':'100:90',
'action':'',
'start':'1',
'limit':'20'
}
response = requests.get(url=url,params=param,headers=headers)
#获取响应数据:json()方法返回的是obj
dic_obj = response.json()
fileNmae = './douban.json'
fp = open(fileNmae,'w',encoding='utf-8')
json.dump(dic_obj,fp=fp,ensure_ascii=False)
print('over!')
1.寻找信息
url='https://movie.douban.com/j/chart/top_list?type=24&interval_id=100%3A90&action=&start=0&limit=20'
数据格式为json
需要的数据可以在response中查看
2.将url中的参数写成字典
param = {
'type':'24',
'interval_id':'100:90',
'action':'',
'start':'1',
'limit':'20'
}
3.将得到的数据在json校验网站处理一下
json在线校验网站