先熟悉下scrapy项目结构:python
scrapyTest/scrapyTest/ _init_.py用来初始化项目信息框架
scrapyTest/scrapyTest/ items.py文件为爬虫项目的数据容器文件,主要用来定义咱们的数据.scrapy
scrapyTest/scrapyTest/ pipelines.py文件为爬虫项目的管道文件,主要用于对items中的数据进行进一步加工与处理ide
scrapyTest/scrapyTest/ settings.py文件为爬虫项目的设置文件,主要为爬虫项目设置一些信息。学习
spider文件夹下放置的是爬虫项目的爬虫部分相关的文件。this
scrapyTest/scrapyTest/spider/ _init_.py文件为爬虫项目中部分代码进行初始化,主要是为spider进行初始化,以上是对scrapy项目的结构进行说明。spa
1. 建立scrapy项目: 好比咱们须要在“D:\python\day1\”这个目录建立项目。日志
直接输入一下命令:code
cd D:\python\day1\ scrapy startproject <projectname> (这里我用scrapyTest来命名)
这里就建立scrapy项目成功ip
咱们进入到建立项目的目录:cd 项目名称
在建立项目过程当中咱们也能够加一些参数进行控制:
输入命令:
scrapy startproject -h
输出以下:
Usage ===== scrapy startproject <project_name> [project_dir] Create new project Options ======= --help, -h show this help message and exit Global Options -------------- --logfile=FILE log file. if omitted stderr will be used --loglevel=LEVEL, -L LEVEL log level (default: DEBUG) --nolog disable logging completely --profile=FILE write python cProfile stats to FILE --pidfile=FILE write process ID to FILE --set=NAME=VALUE, -s NAME=VALUE set/override setting (may be repeated) --pdb enable pdb on failure
--logfile=File用来指定打印日志存放的目录
例如: scrapy startproject --logfile=log.txt scrapyTest