当您需要从某个网站中获取信息,但该网站未提供API或能通过程序获取信息的机制时, Scrapy可以助你一臂之力。
安装
首先准备环境>
yum install gcc libffi-devel openssl-devel libxml2 libxslt-devel libxml2-devel python-devel -y
安装easy_install>
yum install python-setuptools
安装pip>
easy_install pip
安装 lxml>
easy_install lxml
如果以上都顺利,就开始安装scrapy吧>
pip install scrapy
hello项目
创建项目>
scrapy startproject hello
该命令将会创建一个hello目录,就是项目hello的根目录,项目结构如下:
.
|-- hello # 该项目的python模块。之后您将在此加入代码。
| |-- __init__.py ##
| |-- items.py ## 项目中的item文件
| |-- middlewares.py ## 没弄明白
| |-- pipelines.py ## 项目中的pipelines文件
| |-- settings.py ## 项目的设置文件
| `-- spiders ## 放置spider代码的目录
| `-- __init__.py ##
|
`-- scrapy.cfg ## 项目的配置文件
注意: 右边的##
是我为了方便理解标明的注释