V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2014-11-24 10:52:17 +08:00 · 9023 次点击
    这是一个创建于 3433 天前的主题,其中的信息可能已经有所发展或是发生改变。
    5 条回复    2016-11-22 09:54:32 +08:00
    lilixiang999
        1
    lilixiang999  
       2014-11-24 12:57:43 +08:00
    tommark
        2
    tommark  
    OP
       2014-11-24 13:10:18 +08:00
    @lilixiang999 这个是自己创建了一个json文件,然后写出去,想问一下怎么让scrapy的 JsonLinesItemExporter自己能输出utf-8的中文
    Jordan
        3
    Jordan  
       2014-11-24 14:56:03 +08:00
    自己动手丰衣足食,尝试搜索一下源码,找到json.dump()或者json.dumps()调用,加上ensure_ascii=False
    lilixiang999
        4
    lilixiang999  
       2014-11-24 17:12:50 +08:00   ❤️ 1
    我是在pipeline 调用JsonItemExporter方法的时候传递ensure_ascii=False就ok了,http://segmentfault.com/q/1010000000367894
    caoyujia2000
        5
    caoyujia2000  
       2016-11-22 09:54:32 +08:00
    遇到同样的问题,楼上的方法正解
    def spider_opened(self, spider):
    self.file = open('date.json', 'wb')
    self.exporter = JsonItemExporter(self.file,ensure_ascii=False)
    self.exporter.start_exporting()
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3202 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 13:38 · PVG 21:38 · LAX 06:38 · JFK 09:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.