Scrapy 第一个示例

前置条件

  安装python3.6 +

  安装vs code

  scrapy 包安装  pip3 install scrapy

一.打开vs code ,在终端输入命令, Scrapy创建项目,这样项目就创建在F:\python_work\scrapy_Sample\tutorial 文件夹中

PS F:\python_work\scrapy_Sample> scrapy startproject tutorial

二.在spiders文件夹下创建quotes_spider.py文件,并输入以下代码

  

   name :是爬虫标识,它在一个项目中必须是唯一的。

  start_requests():必须返回一个可迭代的 Requests

  parse(): 将被调用以处理为每个请求下载的响应的方法

  open() :保存下载的html文件

 

 三.启动爬取

PS F:\python_work\scrapy_Sample\tutorial> scrapy crawl quotes

  在打印日志查看到文件已保存

 

 

  参考文档:https://docs.scrapy.org/en/latest/intro/tutorial.html#our-first-spider

 

posted on 2022-12-26 12:09  花阴偷移  阅读(1)  评论(0编辑  收藏  举报

导航