python爬虫之scrapy框架(一)————scrapy框架理论和环境的搭建

一、搭建环境

       1、Scrapy框架是一个异步框架

       2、基于Twiisted库(Twiisted库又依赖于Lxml库,所以要首先安装lxml库)

       3、升级piip工具:python -m pip install -U pip

       4、安装步骤:

              (1)安装lxml:pip3 install lxml

              (2)安装twisted:pip3 install twisted

              (3)安装scrapy:pip3 install scrapy

              (4)安装关联模块pypiwin32:pip3 install pypiwin32

 

二、Scrapy框架的使用

       1、运行图:

python爬虫之scrapy框架(一)————scrapy框架理论和环境的搭建

2、创建项目

       运行命令:scrapy startproject 项目名称

3、项目目录结构

python爬虫之scrapy框架(一)————scrapy框架理论和环境的搭建

(1)scrapy.cfg(配置文件)

(2)item.py:

python爬虫之scrapy框架(一)————scrapy框架理论和环境的搭建

              在item中定义用于存储爬取到的数据的数据模型

(3)middlewares.py:

              一般用于存储中间件的数据

(4)piplines.py:

              将返回的数据进行存储

(5)settings.py:

              整个项目的设置文件