weixin_43884285
weixin_43884285
2019-01-10 11:32

关于json.load()里报错的问题:json.decoder.JSONDecodeError:

  • python
  • json

用python爬猫眼电影,代码和老师讲的一样的,但是出现了一些问题:

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

from urllib import request
import json


def get_data(url):
    headers = {
        'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1'
    }
    req = request.Request(url, headers=headers)
    response = request.urlopen(req)
    if response.getcode() == 200:
        print(response.read())
        return response.read()


def parse_data(html):
    data = json.loads(html)['cmts']
    print(data)


if __name__ == '__main__':
    url = 'http://m.maoyan.com/mmdb/comments/movie/1203084.json?_v_=yes&offset=15&startTime=2018-09-01%2011%3A10%3A00'
    parse_data(get_data(url))

报错如下:
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐

换一换