zoukankan      html  css  js  c++  java
  • Python开源框架Scrapy安装及使用

    一、安装问题
    环境: 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')
  • 相关阅读:
    python 中的[::-1]
    python 闭包
    elastic
    文件上传进度条修改
    python decorator的理解
    同方爬虫--面试题
    js typeof
    浅谈软件项目实施
    数独·唯一性技巧(Uniqueness)-1
    数独二
  • 原文地址:https://www.cnblogs.com/moye/p/3602182.html
Copyright © 2011-2022 走看看