鱼C论坛

 找回密码
 立即注册
查看: 2469|回复: 1

[已解决]求助,代码哪里错了。抄的作业跑步起来

[复制链接]
发表于 2022-4-10 17:24:36 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. import requests
  2. import json

  3. if __name__ == "__main__":
  4.     url = "https://movie.douban.com/j/chart/top_list"
  5.     param = {
  6.         "type": "24",
  7.         "interval_id": "100:90",
  8.         "action": "",
  9.         "start": "0",
  10.         "limit": "20"
  11.     }
  12.     headers = {
  13.         "User - Agent": "Mozilla / 5.0(Windows NT 10.0;Win64;x64)"
  14.                         " AppleWebKit / 537.36(KHTML, likeGecko) "
  15.                         "Chrome / 100.0.4896.75Safari / 537.36Edg / 100.0.1185.36"
  16.     }

  17.     response = requests.get(url=url,params=param,headers=headers)
  18.     list_data = response.json()
  19.     fp = open("douban.json","w",encoding = "utf-8")
  20.     json.dump(list_data,fp=fp,ensure_ascii=False)
  21.     print('over!!!')
复制代码


raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: [Errno Expecting value] : 0
最佳答案
2022-4-10 23:22:54
  1. import requests
  2. import json

  3. if __name__ == "__main__":
  4.     url = "https://movie.douban.com/j/chart/top_list"
  5.     param = {
  6.         "type": "24",
  7.         "interval_id": "100:90",
  8.         "action": "",
  9.         "start": "0",
  10.         "limit": "20"
  11.     }
  12.     headers = {
  13.         "User-Agent": "Mozilla / 5.0(Windows NT 10.0;Win64;x64)"              # User-Agent 中间不要空格
  14.                         " AppleWebKit / 537.36(KHTML, likeGecko) "
  15.                         "Chrome / 100.0.4896.75Safari / 537.36Edg / 100.0.1185.36"
  16.     }

  17.     response = requests.get(url=url,params=param,headers=headers)
  18.     list_data = response.json()
  19.     fp = open("douban.json","w",encoding = "utf-8")
  20.     json.dump(list_data,fp=fp,ensure_ascii=False)
  21.     print('over!!!')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-4-10 23:22:54 | 显示全部楼层    本楼为最佳答案   
  1. import requests
  2. import json

  3. if __name__ == "__main__":
  4.     url = "https://movie.douban.com/j/chart/top_list"
  5.     param = {
  6.         "type": "24",
  7.         "interval_id": "100:90",
  8.         "action": "",
  9.         "start": "0",
  10.         "limit": "20"
  11.     }
  12.     headers = {
  13.         "User-Agent": "Mozilla / 5.0(Windows NT 10.0;Win64;x64)"              # User-Agent 中间不要空格
  14.                         " AppleWebKit / 537.36(KHTML, likeGecko) "
  15.                         "Chrome / 100.0.4896.75Safari / 537.36Edg / 100.0.1185.36"
  16.     }

  17.     response = requests.get(url=url,params=param,headers=headers)
  18.     list_data = response.json()
  19.     fp = open("douban.json","w",encoding = "utf-8")
  20.     json.dump(list_data,fp=fp,ensure_ascii=False)
  21.     print('over!!!')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-6 13:37

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表