get请求传递参数是通过params传递
如果参数正确返回却为空时,可以查看是否为格式问题
对于第三个参数,指定编码方式必须要加encoding=""
该提示字面意思是:只能将list类型和list类型联系起来,而不是str类型
要保证类型一致
.json()处理json数据
import requests
url = "https://movie.douban.com/j/chart/top_list"
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '
'(KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.14'
'18.56'
}
param = {
'type': '13',
'interval_id':'100:90',
'action': '',
'start': '0',
'limit': '20'
}
response = requests.get(url=url,headers=headers,params=param)
response = response.json()
# print(response)
fp = open('./doubanBook.txt','w',encoding='utf-8')
for i in response:
title = i['title']
release_date = i['release_date']
score = i['score']
actors = i['actors']
fp.write(title + '\n' + release_date + '\n' + score + '\n' + '\n')
标签:title,list,score,release,基本操作,requests,response
From: https://www.cnblogs.com/arsonist/p/16936718.html