Python --- Scrapy 命令(转)
Scrapy 命令 分为两种: 全局命令 和 项目命令 。
全局命令:在哪里都能使用。
项目命令:必须在爬虫项目里面才能使用。
全局命令
C:\Users\AOBO>scrapy -h
Scrapy 1.2. - no active project Usage:
scrapy <command> [options] [args] Available commands:
bench Run quick benchmark test
commands
fetch Fetch a URL using the Scrapy downloader
genspider Generate new spider using pre-defined templates
runspider Run a self-contained spider (without creating a project)
settings Get settings values
shell Interactive scraping console
startproject Create new project
version Print Scrapy version
view Open URL in browser, as seen by Scrapy [ more ] More commands available when run from project directory Use "scrapy <command> -h" to see more info about a command
- startproject :创建一个爬虫项目:
scrapy startproject demo
(demo
创建的爬虫项目的名字) - runspider 运用单独一个爬虫文件:
scrapy runspider abc.py
- veiw 下载一个网页的源代码,并在默认的文本编辑器中打开这个源代码:
scrapy view http://www.aobossir.com/
- shell 进入交互终端,用于爬虫的调试(如果你不调试,那么就不常用):
scrapy shell http://www.baidu.com --nolog
(--nolog
不显示日志信息) - version 查看版本:(
scrapy version
) - bench 测试本地硬件性能(工作原理:):
scrapy bench
(如果遇到问题:解决问题:import win32api ImportError: DLL load failed
,到这里查看解决办法。)
项目命令
(进入项目路径,才能看到项目命令)
D:\BaiduYunDownload\first>scrapy -h
Scrapy 1.2. - project: first Usage:
scrapy <command> [options] [args] Available commands:
bench Run quick benchmark test
check Check spider contracts
commands
crawl Run a spider
edit Edit spider
fetch Fetch a URL using the Scrapy downloader
genspider Generate new spider using pre-defined templates
list List available spiders
parse Parse URL (using its spider) and print the results
runspider Run a self-contained spider (without creating a project)
settings Get settings values
shell Interactive scraping console
startproject Create new project
version Print Scrapy version
view Open URL in browser, as seen by Scrapy Use "scrapy <command> -h" to see more info about a command D:\BaiduYunDownload\first>
- genspider 创建一个爬虫文件,我们在爬虫项目里面才能创建爬虫文件(这个命令用的非常多)( startproject :创建一个爬虫项目)。创建爬虫文件是按照以下模板来创建的,使用
scrapy genspider -l
命令查看有哪些模板。
D:\BaiduYunDownload\first>scrapy genspider -l
Available templates:
basic
crawl
csvfeed
xmlfeed D:\BaiduYunDownload\first>
basic
基础 crawl
自动爬虫 csvfeed
用来处理csv文件 xmlfeed
用来处理xml文件
按照 basic
模板创建一个名为 f1
的爬虫文件: scrapy genspider -t basic f1
,创建了一个 f1.py
文件。
check测试爬虫文件、或者说:检测一个爬虫,如果结果是:OK,那么说明结果没有问题。:
scrapy check f1
crawl运行一个爬虫文件。:
scrapy crawl f1
或者scrapy crawl f1 --nolog
list列出当前爬虫项目下所有的爬虫文件:
scrapy list
edit使用编辑器打开爬虫文件 (Windows上似乎有问题,Linux上没有问题):
scrapy edit f1
scrapy使用
scrapy startproject myproject
cd myproject
scrapy genspider -t basic stackoverflow stackoverflow.com/questions?sort=votes
scrapy crawl stackoverflow -o items.json(运行爬虫并把结果保存为json,也支持csv)
Python --- Scrapy 命令(转)的更多相关文章
- Python -- Scrapy 命令行工具(command line tools)
结合scrapy 官方文档,进行学习,并整理了部分自己学习实践的内容 Scrapy是通过 scrapy 命令行工具进行控制的. 这里我们称之为 “Scrapy tool” 以用来和子命令进行区分. 对 ...
- python爬虫scrapy命令工具学习之篇三
命令行工具(Command line tools) 全局命令 startproject settings runspider shell fetch view version 项目命令 crawl c ...
- Python.Scrapy.14-scrapy-source-code-analysis-part-4
Scrapy 源代码分析系列-4 scrapy.commands 子包 子包scrapy.commands定义了在命令scrapy中使用的子命令(subcommand): bench, check, ...
- Python.Scrapy.11-scrapy-source-code-analysis-part-1
Scrapy 源代码分析系列-1 spider, spidermanager, crawler, cmdline, command 分析的源代码版本是0.24.6, url: https://gith ...
- Python -- Scrapy 框架简单介绍(Scrapy 安装及项目创建)
Python -- Scrapy 框架简单介绍 最近在学习python 爬虫,先后了解学习urllib.urllib2.requests等,后来发现爬虫也有很多框架,而推荐学习最多就是Scrapy框架 ...
- Scrapy命令行工具简介
Windows 10家庭中文版,Python 3.6.4,virtualenv 16.0.0,Scrapy 1.5.0, 在最初使用Scrapy时,使用编辑器或IDE手动编写模块来创建爬虫(Spide ...
- 使用Scrapy命令行工具【导出JSON文件】时编码设置
Windows 10家庭中文版,Python 3.6.4,virtualenv 16.0.0,Scrapy 1.5.0, 使用scrapy命令行工具建立了爬虫项目(startproject),并使用s ...
- (19)python scrapy框架
安装scrapy pycharm 建个纯python工程 settings里 环境变量设置 C:\Python27;C:\Python27\Scripts; 下载win32api https://so ...
- 二、Scrapy命令行工具
本文转载自以下链接:https://scrapy-chs.readthedocs.io/zh_CN/latest/topics/commands.html Scrapy是通过 scrapy 命令行工具 ...
随机推荐
- Codeforces 629 B. Far Relative’s Problem
B. Far Relative’s Problem time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- HDU 1060 Leftmost Digit【log10/求N^N的最高位数字是多少】
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- NWU现场赛——解题报告
负二进制转换 Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Problem Desc ...
- Light oj 1125 - Divisible Group Sums (dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1125 题意: 给你n个数,q次询问,每次询问问你取其中m个数是d的整数倍的方案 ...
- 深入理解 JavaScript Function
1.Function Arguments JavaScript 函数的参数 类型可以是 复杂类型如 Object or Array 和简单类型 String Integer null undefin ...
- visual studio 2010 调试
非startup project网站 通过attach to process 添加进程w3wp可以实现断点调试 若有多个,可以在iis中添加应用程序池,然后在网站的高级设置里设置应用程序池里,选择对 ...
- RecyclerView的滚动事件分析
列表的滚动一般分为两种: 手指按下 -> 手指拖拽列表移动 -> 手指停止拖拽 -> 抬起手指 手指按下 -> 手指快速拖拽后抬起手指 -> 列表继续滚动 -> 停 ...
- 【共享单车】—— React后台管理系统开发手记:Router 4.0路由实战演练
前言:以下内容基于React全家桶+AntD实战课程的学习实践过程记录.最终成果github地址:https://github.com/66Web/react-antd-manager,欢迎star. ...
- 【唯星宠物】——BootStrap/Mysql/PHP/Ajax爬坑之正则验证登录注册子页
前言:唯星宠物产品官网的登录注册,单独一个子页,页面使用BootStrap实现响应式,PHP提供服务端,利用Ajax技术,从Mysql中获取JSON数据,并对表单信息进行正则验证.项目github地址 ...
- 2017.2.13 开涛shiro教程-第十二章-与Spring集成(一)配置文件详解
原博客地址:http://jinnianshilongnian.iteye.com/blog/2018398 根据下载的pdf学习. 第十二章-与Spring集成(一)配置文件详解 1.pom.xml ...