推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
tommark
V2EX  ›  Python

scrapy 使用 feed export 保存为 json 文件时如何保存 utf-8 的中文,而不是\uxxxx 这样的代码?

  •  
  •   tommark · Nov 24, 2014 · 10218 views
    This topic created in 4323 days ago, the information mentioned may be changed or developed.
    5 replies  •  2016-11-22 09:54:32 +08:00
    LukeLeeee
        1
    LukeLeeee  
       Nov 24, 2014
    tommark
        2
    tommark  
    OP
       Nov 24, 2014
    @lilixiang999 这个是自己创建了一个json文件,然后写出去,想问一下怎么让scrapy的 JsonLinesItemExporter自己能输出utf-8的中文
    Jordan
        3
    Jordan  
       Nov 24, 2014
    自己动手丰衣足食,尝试搜索一下源码,找到json.dump()或者json.dumps()调用,加上ensure_ascii=False
    LukeLeeee
        4
    LukeLeeee  
       Nov 24, 2014   ❤️ 1
    我是在pipeline 调用JsonItemExporter方法的时候传递ensure_ascii=False就ok了,http://segmentfault.com/q/1010000000367894
    caoyujia2000
        5
    caoyujia2000  
       Nov 22, 2016
    遇到同样的问题,楼上的方法正解
    def spider_opened(self, spider):
    self.file = open('date.json', 'wb')
    self.exporter = JsonItemExporter(self.file,ensure_ascii=False)
    self.exporter.start_exporting()
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2636 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 13:25 · PVG 21:25 · LAX 06:25 · JFK 09:25
    ♥ Do have faith in what you're doing.