Python Spider之Scrapy(二): scrapy初窥1
scrapy初窥
1 scrapy中文文档:http://scrapy-chs.readthedocs.org/zh_CN/latest/index.html 2 scrapy创建project:scrapy startproject xx
一.scrapy创建文件后文件目录介绍:
在cmd命令行中输入如下命令后:scrapy startproject tutorial
scrapy startproject tutorial将会创建包含下列内容的xx目录:
tutorial/ scrapy.cfg tutorial/ __init__.py items.py pipelines.py settings.py spiders/ __init__.py ...
.cfg文件所在的目录即为根目录Items.py定义需要抓取并需要后期处理的数据。
settings.py文件配置Scrapy,从而修改user-agent,设定爬取时间间隔,设置代理,配置各种中间件等等。
pipeline.py用于存放执行后期数据处理的功能,从而使得数据的爬取和处理分开。
二:启动scrapy
1.可用命令启动
2.在project的根目录下创建一个main.py文件,并且写入命令,直接运行main.py文件即可。
from scrapy import cmdline cmdline.execute("scrapy crawl xxx".split())
注:xxx为你的爬虫的名字。
三:创建爬虫文件
爬虫文件放在spiders/ 目录中
注:爬虫py文件的名称与你的目录的名称不要重复
浙公网安备 33010602011771号