scrapy爬虫
创建项目
scrapy startproject 项目名
创建一个名为itcast的爬虫,并指定爬取域的范围
scrapy genspider itcast “itcast.cn”
scrapy crawl 项目名 -------------启动爬虫
scrapy-redis分布式爬虫启动项目
scrapy runspider 项目名.py
redis-cli -h windows端ip
lpush 项目名 目标网址
scrapy保存信息的最简单的方法主要有四种,-o 输出指定格式的文件,,命令如下:
json格式,默认为Unicode编码
scrapy crawl itcast -o teachers.json
json lines格式,默认为Unicode编码
scrapy crawl itcast -o teachers.jsonl
csv 逗号表达式,可用Excel打开
scrapy crawl itcast -o teachers.csv
xml格式
scrapy crawl itcast -o teachers.xml
创建Rule规则的爬虫
scrapy genspider -t crawl Itcast ‘itcast.cn’
scrapy crawl 项目名 --nolog