scrapy抓取到中文,保存到json文件为unicode,如何解决.
http://scrapy-chs.readthedocs.org/zh_CN/latest/intro/overview.html
以上链接是很好的scrapy学些资料.感谢marchtea的翻译.
在学习过程中,碰到一个很棘手的问题: 中文的显示和存储. (中文在控制台显示的为\u77e5\u540d...这样的字符,保存到文件也是这样的)
在网上找了很久,下面这个链接应是最切题的.
http://stackoverflow.com/questions/9181214/scrapy-text-encoding
摘抄如下:
pipelines.py:
import json
import codecs class JsonWithEncodingPipeline(object): def __init__(self):
self.file = codecs.open('scraped_data_utf8.json', 'w', encoding='utf-8') def process_item(self, item, spider):
line = json.dumps(dict(item), ensure_ascii=False) + "\n"
self.file.write(line)
return item def spider_closed(self, spider):
self.file.close()
按照上面的方法,输出到文件就是正常的中文了.
搜索关键字和链接:
JsonItemExporter ensure_ascii=False
JsonItemExporter uxxx
python输出json文件\uxxx如何转换成中文
Decode and Encode in Python [ http://yangpengg.github.io/blog/2012/12/13/decode-and-encode-in-python/ ]
--
python print输出的是中文但是输出到文件的是\uxxx
http://wklken.me/posts/2013/08/31/python-extra-coding-intro.html Scrapy : storing the data
http://stackoverflow.com/questions/14073442/scrapy-storing-the-data scrapy 使用item export输出中文到json文件,内容为unicode码,如何输出为中文?
http://www.lefern.com/question/15837/scrapy-shi-yong-item-exportshu-chu-zhong-wen-dao-jsonwen-jian-nei-rong-wei-unicodema-ru-he-shu-chu-wei-zhong-wen/ how to put in json utf-8 symbols, not their codes?
https://groups.google.com/forum/#!msg/scrapy-users/rJcfSFVZ3O4/ZYsD7CMoCKMJ scrapy text encoding
http://stackoverflow.com/questions/9181214/scrapy-text-encoding
scrapy抓取到中文,保存到json文件为unicode,如何解决.的更多相关文章
- 关于爬取数据保存到json文件,中文是unicode解决方式
流程: 爬取的数据处理为列表,包含字典.里面包含中文, 经过json.dumps,保存到json文件中, 发现里面的中文显示未\ue768这样子 查阅资料发现,json.dumps 有一个参数.ens ...
- python scrapy实战糗事百科保存到json文件里
编写qsbk_spider.py爬虫文件 # -*- coding: utf-8 -*- import scrapy from qsbk.items import QsbkItem from scra ...
- 使用scrapy爬取的数据保存到CSV文件中,不使用命令
pipelines.py文件中 import codecs import csv # 保存到CSV文件中 class CsvPipeline(object): def __init__(self): ...
- 记录python爬取猫眼票房排行榜(带stonefont字体网页),保存到text文件,csv文件和MongoDB数据库中
猫眼票房排行榜页面显示如下: 注意右边的票房数据显示,爬下来的数据是这样显示的: 网页源代码中是这样显示的: 这是因为网页中使用了某种字体的缘故,分析源代码可知: 亲测可行: 代码中获取的是国内票房榜 ...
- iOS开发——数据持久化&本地数据的存储(使用NSCoder将对象保存到.plist文件)
本地数据的存储(使用NSCoder将对象保存到.plist文件) 下面通过一个例子将联系人数据保存到沙盒的“documents”目录中.(联系人是一个数组集合,内部为自定义对象). 功能如下: ...
- np.savetxt()——将array保存到txt文件,并保持原格式
问题:1.如何将array保存到txt文件中?2.如何将存到txt文件中的数据读出为ndarray类型? 需求:科学计算中,往往需要将运算结果(array类型)保存到本地,以便进行后续的数据分析. 解 ...
- ffmpeg学习(二) 通过rtsp获取H264裸流并保存到mp4文件
本篇将使用上节http://www.cnblogs.com/wenjingu/p/3977015.html中编译好的库文件通过rtsp获取网络上的h264裸流并保存到mp4文件中. 1.VS2010建 ...
- python爬取当当网的书籍信息并保存到csv文件
python爬取当当网的书籍信息并保存到csv文件 依赖的库: requests #用来获取页面内容 BeautifulSoup #opython3不能安装BeautifulSoup,但可以安装Bea ...
- 使用pandas中的raad_html函数爬取TOP500超级计算机表格数据并保存到csv文件和mysql数据库中
参考链接:https://www.makcyun.top/web_scraping_withpython2.html #!/usr/bin/env python # -*- coding: utf-8 ...
随机推荐
- HW5.2
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- Learning JavaScript Design Patterns The Singleton Pattern
The Singleton Pattern The Singleton pattern is thus known because it restricts instantiation of a cl ...
- 检查REDO日志相关信息并生成HTML文件的脚本
生成HTML格式的文件 内容有: 检查数据库版本.REDO日志组情况, 最近20次日志切换频率检查--日志间的归档时间间隔, 这对查看数据库的IO繁忙时段 统计指定日期当天每小时的归档日志产生量--日 ...
- Install Package and Software
svn http://tortoisesvn.sourceforge.net/ git https://download.tortoisegit.org/ http://git-for-windows ...
- 六款值得推荐的android(安卓)开源框架简介【转】
http://my.oschina.net/u/1244156/blog/380647 1.volley 项目地址 https://github.com/smanikandan14/Volley-de ...
- iOS 中UI控件的各种对齐方式总结
1.textAligment : 文字的水平方向的对齐方式 取值 NSTextAlignmentLeft = 0, // 左对齐 NSTextAlignmentCenter = ...
- 从源码角度深入分析ant
Ant的基本概念 首先是ant的基本概念:Project,Target,Tasks,Properties,Paths 1.Project <project> build.xml文件最顶层的 ...
- linux监控程序
IP内部地址: 方法一:ifconfig |grep 'inet addr'|grep '192.168.1' | awk '{print $2}'| tr -d "addr:" ...
- Java 实现折半查找
package search; import java.util.*; /*折半查找要求线性表是有序的,假设递增 * 基本思路:R[low...high]是当前的查找区间,首先确定中间位置mid=(l ...
- iOS 网络编程:AFNetworking
1 简介 1.1 概念 AFNetworking网络框架并不是IOS自带的框架,而是第三方的开源框架.它是对NSURLConnection和NSURLSession API的封装,但是目前AFNetw ...