【问题标题】:json.decoder.JSONDecodeError: While Parsing data form an API contains Japanese Charactersjson.decoder.JSONDecodeError:当从 API 解析数据时包含日语字符
【发布时间】:2021-07-11 20:41:33
【问题描述】:

我试图用ScrapyJSON 解析API 响应,但它给我一个错误json.decoder.JSONDecodeError:

我尝试了来自here 的所有日语encoding 类型,但没有一个有效。希望大家有解决办法。

下面是我的代码:

import scrapy
import json

class MakuakeSpider(scrapy.Spider):
    name = 'makuake'
    start_urls = ['https://api.makuake.com/v2/projects?page=1&per_page=15&category_code=technology']

    def parse(self, response):
        json_rsp = json.loads(response.body).encode("encoding-type-jps").decode("utf-8")
        print(json_rsp)

【问题讨论】:

    标签: python json scrapy


    【解决方案1】:

    试试这个response.text

    import scrapy
    import json
    
    class MakuakeSpider(scrapy.Spider):
        name = 'makuake'
        start_urls = ['https://api.makuake.com/v2/projects?page=1&per_page=15&category_code=technology']
    
        def parse(self, response):
            json_rsp = json.loads(response.text)
            print(json_rsp)
    

    【讨论】:

      猜你喜欢
      • 2011-07-21
      • 2018-06-19
      • 2012-04-14
      • 2012-05-23
      • 1970-01-01
      • 1970-01-01
      • 2014-06-22
      • 2012-08-09
      • 1970-01-01
      相关资源
      最近更新 更多