1、安装scrapy

2、创建爬虫项目 scrapy startproject test_scrapy

3、创建quotes_spider.py文件
4、复制下面代码到quotes_spider.py文件
import scrapy #导入模块
#编写QuotesSpider类
class QuotesSpider(scrapy.Spider):
name = "quotes"
#爬取网站地址
start_urls = [
'http://quotes.toscrape.com/tag/humor/',
]
def parse(self, response): #定义解析方法
for quote in response.css('div.quote'): #解析class="quote"的div
#采用字典记录,爬取内容部分定义
yield {
'text': quote.css('span.text::text').extract_first(),
'author': quote.xpath('span/small/text()').extract_first(),
}
#下一页地址
next_page = response.css('li.next a::attr("href")').extract_first()
if next_page is not None:
yield response.follow(next_page, self.parse)
5、cd test_scrapy 到quotes_spider.py文件目录
6、运行scrapy runspider quotes_spider.py -o quotes.json命令
可看到目录下多了quotes.json文件
打开quotes文件可看到
[
{"text": "\u201cThe person, be it gentleman or lady, who has not pleasure in a good novel, must be intolerably stupid.\u201d", "author": "Jane Austen"},
{"text": "\u201cA day without sunshine is like, you know, night.\u201d", "author": "Steve Martin"},
{"text": "\u201cAnyone who thinks sitting in church can make you a Christian must also think that sitting in a garage can make you a car.\u201d", "author": "Garrison Keillor"},
{"text": "\u201cBeauty is in the eye of the beholder and it may be necessary from time to time to give a stupid or misinformed beholder a black eye.\u201d", "author": "Jim Henson"},
{"text": "\u201cAll you need is love. But a little chocolate now and then doesn't hurt.\u201d", "author": "Charles M. Schulz"},
{"text": "\u201cRemember, we're madly in love, so it's all right to kiss me anytime you feel like it.\u201d", "author": "Suzanne Collins"},
{"text": "\u201cSome people never go crazy. What truly horrible lives they must lead.\u201d", "author": "Charles Bukowski"},
{"text": "\u201cThe trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.\u201d", "author": "Terry Pratchett"},
{"text": "\u201cThink left and think right and think low and think high. Oh, the thinks you can think up if only you try!\u201d", "author": "Dr. Seuss"},
{"text": "\u201cThe reason I talk to myself is because I\u2019m the only one whose answers I accept.\u201d", "author": "George Carlin"},
{"text": "\u201cI am free of all prejudice. I hate everyone equally. \u201d", "author": "W.C. Fields"},
{"text": "\u201cA lady's imagination is very rapid; it jumps from admiration to love, from love to matrimony in a moment.\u201d", "author": "Jane Austen"}
]
 

Scrapy at a glance预览的更多相关文章

  1. Word/Excel 在线预览

    前言 近日项目中做到一个功能,需要上传附件后能够在线预览.之前也没做过这类似的,于是乎就查找了相关资料,.net实现Office文件预览大概有这几种方式: ① 使用Microsoft的Office组件 ...

  2. 预览github里面的网页或dome

    1.问题所在: 之前把项目提交到github都可以在路径前面加上http://htmlpreview.github.io/?来预览demo,最近发现这种方式预览的时候加载不出来css,js(原因不详) ...

  3. IE8/9 本地预览上传图片

    本地预览的意思是,在选择图片之后先不上传到服务器,而是由一个<img>标签来预览本地的图片,非 IE8/9 浏览器可以从<input type="file"/&g ...

  4. JS图片上传预览插件制作(兼容到IE6)

    其实,图片预览功能非常地常见.很意外,之前遇到上传图片的时候都不需要预览,也一直没有去实现过.现在手上的项目又需要有图片预览功能,所以就动手做了一个小插件.在此分享一下思路. 一.实现图片预览的一些方 ...

  5. [干货来袭]MSSQL Server on Linux预览版安装教程(先帮大家踩坑)

    前言 昨天晚上微软爸爸开了全国开发者大会,会上的内容,我就不多说了,园子里面很多.. 我们唐总裁在今年曾今透漏过SQL Server love Linux,果不其然,这次开发者大会上就推出了MSSQL ...

  6. 微软发布 Windows Server 2016 预览版第三版,开发者要重点关注Nano Server

    微软已经发布 Windows Server 2016 和 System Center 2016 第三个技术预览版,已经提供下载.Windows Server 2016 技术预览版第三版也是首个包括了容 ...

  7. Visual Studio Code预览版Ver 0.3.0试用体验

    当你开始阅读这篇文章时,请先不要把Visual Studio Code和.net.Windows联想到一起,因为VS Code是一个跨平台,支持30多种语言的开箱代码编辑器.不管你是.Net.Java ...

  8. UploadFile控件,提交图片后,页面预览显示刚刚提交的图片

    最近在用asp.net来写一个新闻系统后台,然后由于不用用网上的flash插件来上传图片什么的,我就用asp.net的控件来写,但是控件总归有一些用的不够灵活的地方.这次测试提出,文章在修改的时候,需 ...

  9. JS魔法堂之实战:纯前端的图片预览

    一.前言 图片上传是一个普通不过的功能,而图片预览就是就是上传功能中必不可少的子功能了.在这之前,我曾经通过订阅input[type=file]元素的onchange事件,一旦更改路径则将图片上传至服 ...

随机推荐

  1. 【网页加速】lua redis的二次升级

    之前发过openresty的相关文章,也是用于加速网页速度的,但是上次没有优化好代码,这次整理了下,优化了nginx的配置和lua的代码,感兴趣的话可以看看上篇的文章: https://www.cnb ...

  2. NiftyNet项目介绍

    NiftyNet项目介绍  简述  NiftyNet是一款开源的卷积神经网络平台,旨在通过实现医学图像分析的深度学习方法和模块,支持快速原型和再现性,由WEISS (Wellcome EPSRC Ce ...

  3. SpringBoot报错:java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;

    错误:java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String ...

  4. 第2章 细说Linux系统用户/组管理(1)

    2.1 用户和组的基本概念 用户和组是操作系统中一种身份认证资源. 每个用户都有用户名.用户的唯一编号uid(user id).所属组及其默认的shell,可能还有密码.家目录.附属组.注释信息等. ...

  5. haproxy配置示例和需要考虑的问题

    HaProxy系列文章:http://www.cnblogs.com/f-ck-need-u/p/7576137.html haproxy是一个非常优秀的负载均衡工具,它的特性非常丰富,功能也非常非常 ...

  6. Perl的特殊代码块:BEGIN、CHECK、INIT、END和UNITCHECK

    这是5个特殊的代码块.要理解这几个块,关键在于几个时间点: (1).程序编译期间 (2).程序执行期间 (3).程序执行结束但还未退出期间 BEGIN块 BEGIN块是在程序编译期间执行的,也就是上面 ...

  7. PHP学习笔记(3)-Zend Studio安装和汉化

    下载 因为FQ也慢,所以还是在百度软件中心下载快一些.地址:http://rj.baidu.com/soft/detail/15423.html?ald 因为下载不是最新版本,虽然因为强迫症FQ在官网 ...

  8. [转]调整 VirtualBox 虚拟机的磁盘大小

    本文转自:https://cnzhx.net/blog/resizing-lvm-centos-virtualbox-guest/ 发表于 2013-08-20 作者 H Zeng 更新于 2016- ...

  9. C#装箱和拆箱。

    装箱:值类型-->引用类型. 拆箱:引用类型-->值类型 装箱:把值类型拷贝一份到堆里.反之拆箱. 具有父子关系 是拆装箱的条件之一. 所以: class Program { static ...

  10. c#实战开发:以太坊私链搭建(一)

    1.第一步环境搭建 运行环境:window  客户端版本:Go语言geth 下载地址https://ethereum.github.io/go-ethereum/downloads/ 以太坊API中文 ...