ty540583827 2019-03-14 10:35 采纳率: 75%
浏览 3625
已采纳

python错误:ValueError: No JSON object could be decoded

#-*- coding:utf-8 -*-

import requests

from operator import itemgetter

执行API调用并存储响应

url = 'http://hacker-news.firebaseio.com/v0/topstories.json'
r = requests.get(url)
print("Status code:", r.status_code)

处理有关每篇文章的信息

submission_ids = r.json()
submission_dicts = []
for submission_id in submission_ids[:30]:
# 对于每篇文章,都执行一个API调用
url = ('http://hacker-news.firebaseio.com/v0/item/' + str(submission_id) + '.json')
submission_r = requesets.get(url)
print(submisssion_r.status_code)
reponse_dict = submission_r.json()

submission_dict = {
    'title': resopnse_dict['title'],
    'link': 'http://news.ycombinator.com/item?id=' + str(submission_id),
    'comments': response_dict.get('descendants', 0)
    }
submission_dicts.append(submission_dict)

submission_dicts = sorted(submission_dicts, key=itemgetter('comments'), recerse=Ture)

for submission_dict in submission_dicts:
print("/nTitle:", submission_dict['title'])
print("Discussion link:", submission_dict['link'])
print("Comeents", submission_dict['comments'])

  • 写回答

1条回答 默认 最新

  • slevenxulianjie 2019-03-14 10:49
    关注

    代码里有输入错误,
    而且你要获取的url地址,取不到东西

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 vivo手机锁屏密码忘记了需要手机里的资料在百度里搜可以用ADB命令希望帮帮我
  • ¥15 关于#网络#的问题:网络是从楼上引一根网线下来,接了2台傻瓜交换机,也更换了ip还是不行
  • ¥15 资源泄露软件闪退怎么解决?
  • ¥15 CCF-CSP 2023 第三题 解压缩(50%)
  • ¥30 comfyui openpose报错
  • ¥20 Wpf Datarid单元格闪烁效果的实现
  • ¥15 图像分割、图像边缘提取
  • ¥15 sqlserver执行存储过程报错
  • ¥100 nuxt、uniapp、ruoyi-vue 相关发布问题
  • ¥15 浮窗和全屏应用同时存在,全屏应用输入法无法弹出