惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
H
Help Net Security
N
Netflix TechBlog - Medium
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
A
About on SuperTechFans
V
V2EX
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
宝玉的分享
宝玉的分享
aimingoo的专栏
aimingoo的专栏
F
Fortinet All Blogs
博客园 - 【当耐特】
Microsoft Security Blog
Microsoft Security Blog
Martin Fowler
Martin Fowler
I
InfoQ
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
Engineering at Meta
Engineering at Meta
腾讯CDC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
U
Unit 42
The Cloudflare Blog
Y
Y Combinator Blog

博客园 - 莫耶

学习RxJS:Cycle.js 学习RxJS: 导入 [Node.js] Node.js项目的持续集成 [Node.js] 使用node-forge保障Javascript应用的传输安全 [Node.js] 对称加密、公钥加密和RSA [Node.js] DSL in action [Node.js] 使用TypeScript编写Node项目 [Node.js] Node.js中的流 [Node.js] 基于Socket.IO 的私聊 [Node.js] 闭包和高阶函数 [Node.js] Promise,Q及Async [Node.js] Express的测试覆盖率 [Node.js] BDD和Mocha框架 [Node.js] 也说this [Node.js] ECMAScript 6中的生成器及koa小析 [Node.js] 使用File API 异步上传文件 [Node.js] OAuth 2 和 passport框架 [Node.js] Node + Redis 实现分布式Session方案 [Node.js] Cluster,把多核用起来
Python开源框架Scrapy安装及使用
莫耶 · 2014-03-15 · via 博客园 - 莫耶

2014-03-15 16:21  莫耶  阅读(1278)  评论()    收藏  举报

一、安装问题
环境: CentOS  + Python 2.7 + Pip

1) 安装时遇到 ”UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9” 错误,安装libffi-devel 和 Python-devel:

yum install libffi-devel
yum install python-devel

2) 安装 lxml 时 遇到错误,可能是缺少 libxml2-devel 和 libxslt-devel,使用yum安装:
yum install libxslt-devel libxml2-devel

3) 遇到 bz2 错误,则需要:
yum install bzip2-devel

4) 安装 Twisted 时遇到解压错误,需要先手动将twisted 包当下来,自行解压进行安装:
cd ~
wget http://pypi.python.org/packages/source/T/Twisted/Twisted-13.2.0.tar.bz2
tar xjvf Twisted-13.2.0.tar.bz2 
cd Twisted-13.2.0
python2.7 setup.py install     
然后使用 pip 安装 Scrapy:
pip2.7 install Scrapy

二、中文乱码问题
先安装一个chardet:
pip2.7 install chardet

在程序中判断一下输入并转码输出:

text = response.body
content_type = chardet.detect(text)
if content_type['encoding'] != 'UTF-8':
        text = text.decode(content_type['encoding'])
text = text.encode('utf-8')

Creative Commons License