一、安裝問題
環境: 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.bodycontent_type = chardet.detect(text)if content_type['encoding'] != 'UTF-8': text = text.decode(content_type['encoding'])text = text.encode('utf-8')
新聞熱點
疑難解答