Python --- Scrapy 命令(转)

news/2024/7/19 12:16:43 标签: python, 爬虫, shell

Scrapy 命令 分为两种: 全局命令 和 项目命令 。

全局命令:在哪里都能使用。

项目命令:必须在爬虫项目里面才能使用。

全局命令

C:\Users\AOBO>scrapy -h
Scrapy 1.2.1 - 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.1 - 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)

转载于:https://www.cnblogs.com/tianboblog/p/6962908.html


http://www.niftyadmin.cn/n/1535551.html

相关文章

unity3d移动及键鼠状态

gameObject的transform属性可以进行位置、旋转、大小的设置 位置&#xff1a;position&#xff0c;Translate()&#xff0c;位置的移动 旋转&#xff1a;rotate 大小&#xff1a;localScale Vector3内置&#xff1a;up、down、left、right、forward、back、zero。 鼠标判断&…

sql server2008 日志收缩 命令行

---首先备份数据库(含日志文件&#xff09; use myhis go backup database myhis to diskd:\myhis_rzbak go ---设为简单恢复模式 use [master] go alter database myhis set recovery simple with no_wait go alter database myhis set recovery simple go …

debian 7 cron计划任务设置

近期要用到Cron,做计划任务。因为是Debian,用网上的资料总是不可以&#xff0c;后来发现我的系统里有两个Cron进程。分析是由于两个进程造成的&#xff0c;我按说明文件修改的只是某一个进程的&#xff0c;但是该进程有无法生效&#xff0c;所以是无效的。通过查看日志、查找文…

VMWARE ESXI 虚拟硬盘的格式:精简置备(thin provision)、厚置备延迟置零、厚置备置零

1、厚置备延迟置零(默认 default)&#xff1a; 默认的创建格式&#xff0c;创建过程中为虚拟磁盘分配所需空间。创建时不会擦除物理设备上保留的任何数据&#xff0c;没有置零操作&#xff0c;当有IO操作时&#xff0c;需要等待清零操作完成后才能完成IO&#xff0c; 即&#x…

shell脚本获取CPU使用率

##########################################思路&#xff1a;通过/proc/stat获取cpu使用信息&#xff0c;根据cpu使用数值计算&#xff1a;#user - CPU 花在用户模式的时间&#xff0c;即运行应用程序花费的时间#nice - CPU 花在 nice 值大于一般值 0 (即有较低优先级别) …

sql统计某字段出现次数

比如统计某个表中&#xff0c;姓名出现的次数&#xff1a; select xingming,count(*) from biao group by xingming having count(*) > 2要有group by 就可以&#xff01;

java集合的实现细节--ArrayList和LinkedList

ArrayList和LinkedList的实现差异 List代表一种线性表的数据结构&#xff0c;ArrayList则是一种顺序存储的线性表&#xff0c;ArrayList底层采用动态数组的形式保存每一个集合元素&#xff0c;LinkedList则是一种链式存储的线性表&#xff0c;其本质上就是一个双向链表&#x…

unity(使用了NGUI) 在Build时遇见DontSave but is included in the build

错误提示: An asset is marked with HideFlags.DontSave but is included in the build:Asset: Library/unity editor resources(You are probably referencing internal Unity data in your build.)UnityEditor.HostView:OnGUI() 原因:这是由于NGUI字体上不支持中文,而使用uni…