python爬虫豆瓣出错
本帖最后由 c皮皮o 于 2021-7-18 23:13 编辑在爬取豆瓣电影的时候,出错了{:10_266:}
附代码:
import requests
import json
url="https://movie.douban.com/j/new_search_subjects?"
params={
"sort": "U",
"range": "0,10",
"tags":"",
"start": "0",
"genres": "喜剧"
}
headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.70"}
response=requests.get(url=url,params=params,headers=headers)
for each_media in response.json()["data"]:
print(each_media)
f=open("douban.txt","w",encoding="utf-8")
json.dump(each_media,f,ensure_ascil=False)
f.close()
print("over!!!")
出现下面的错误:
TypeError: __init__() got an unexpected keyword argument 'ensure_ascil'
怎么解决啊,大佬们。
(我就是想以字典的形式保存数据)
报错原因是参数打错了
json.dump(each_media,f,ensure_ascii=False)
页:
[1]