start

from scrapy.cmdline import execute
execute(['scrapy', 'crawl', 'jokespider'])

  

items.py

import scrapy

class JokejiItem(scrapy.Item):
title=scrapy.Field()
url=scrapy.Field() class ListItem(scrapy.Item):
title=scrapy.Field()
url=scrapy.Field()

  

spider.py

from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule
from jokeji.items import JokejiItem,ListItem class JokespiderSpider(CrawlSpider):
name = 'jokespider'
allowed_domains = ['zizi.cn']
start_urls = ['http://www.zizi.cn'] rules = [
Rule(LinkExtractor(allow=r'/list\w+.htm'), callback='parse_list', follow=True),
Rule(LinkExtractor(allow=r'/jokehtml/\w+/\d+\.htm',deny=(r'/list')), callback='parse_item', follow=True),
] def parse_item(self, response):
item=JokejiItem()
item['title']='from content'
return item def parse_list(self,response):
item=ListItem()
item['url']="from list........"+response.url
return item

  

pipelines.py

class JokejiPipeline(object):
def process_item(self, item, spider):
print(item,item__class__,spider)

 

通过 item__class__ 是什么类来决定如何处理数据

当然 ItemClass() 类里可以加

def __str__(self):

  return 'ItemClass"

更直观.

scrapy instantiation的更多相关文章

  1. scrapy之spiders

    官方文档:https://docs.scrapy.org/en/latest/topics/spiders.html# 一句话总结:spider是定义爬取的动作(是否跟进新的链接)及分析网页结构(提取 ...

  2. Scrapy框架爬虫初探——中关村在线手机参数数据爬取

    关于Scrapy如何安装部署的文章已经相当多了,但是网上实战的例子还不是很多,近来正好在学习该爬虫框架,就简单写了个Spider Demo来实践.作为硬件数码控,我选择了经常光顾的中关村在线的手机页面 ...

  3. scrapy爬虫docker部署

    spider_docker 接我上篇博客,为爬虫引用创建container,包括的模块:scrapy, mongo, celery, rabbitmq,连接https://github.com/Liu ...

  4. scrapy 知乎用户信息爬虫

    zhihu_spider 此项目的功能是爬取知乎用户信息以及人际拓扑关系,爬虫框架使用scrapy,数据存储使用mongo,下载这些数据感觉也没什么用,就当为大家学习scrapy提供一个例子吧.代码地 ...

  5. ubuntu 下安装scrapy

    1.把Scrapy签名的GPG密钥添加到APT的钥匙环中: sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 6272 ...

  6. 网络爬虫:使用Scrapy框架编写一个抓取书籍信息的爬虫服务

      上周学习了BeautifulSoup的基础知识并用它完成了一个网络爬虫( 使用Beautiful Soup编写一个爬虫 系列随笔汇总 ), BeautifulSoup是一个非常流行的Python网 ...

  7. Scrapy:为spider指定pipeline

    当一个Scrapy项目中有多个spider去爬取多个网站时,往往需要多个pipeline,这时就需要为每个spider指定其对应的pipeline. [通过程序来运行spider],可以通过修改配置s ...

  8. scrapy cookies:将cookies保存到文件以及从文件加载cookies

    我在使用scrapy模拟登录新浪微博时,想将登录成功后的cookies保存到本地,下次加载它实现直接登录,省去中间一系列的请求和POST等.关于如何从本次请求中获取并在下次请求中附带上cookies的 ...

  9. Scrapy开发指南

    一.Scrapy简介 Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中. Scrapy基于事件驱动网络框架 Twis ...

随机推荐

  1. [django]restfulapi请求规范

    http://www.ruanyifeng.com/blog/2014/05/restful_api.html 方法及作用: GET(SELECT) :从服务器取出资源(一项或多项). POST(CR ...

  2. github的使用,利用git shell命令行创建仓库并上传

    一.登录到github,新建一个版本仓库 二.在“Repository name”一栏里填写版本仓库的名称,如”test”,Description栏是描述,可填可不填. 默认访问权限为公共,点击”Cr ...

  3. keras实例学习-双向LSTM进行imdb情感分类

    源码:https://github.com/keras-team/keras/blob/master/examples/imdb_bidirectional_lstm.py 及keras中文文档 1. ...

  4. 第一弹:超全Python学习资源整理(入门系列)

    随着人工智能.大数据的时代到来,学习Python的必要性已经显得不言而喻.我经常逛youtube,发现不仅仅是以编程为职业的程序员,证券交易人员,生物老师,高级秘书......甚至许多自由撰稿人,设计 ...

  5. [LeetCode] 240. Search a 2D Matrix II_Medium tag: Binary Search

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  6. [LeetCode] 586. Customer Placing the Largest Number of Orders_Easy tag;SQL

    Query the customer_number from the orders table for the customer who has placed the largest number o ...

  7. vim复制粘贴快捷键

    mac下vim复制数据到剪切板: 查看目录是否支持 vim --version |grep "clipboard"

  8. export,import ,export default 彻底弄痛

    ES6模块主要有两个功能:export和import 说白了就是一个淡出一个导入,就相当于以前的公共js样,哪个页面要用,就script 引入这个js  ,然后  无耻的调用这个js中的方法了. ex ...

  9. ASP.Net Core 2.2 MVC入门到基本使用系列 (三)(转)

    本教程会对基本的.Net Core 进行一个大概的且不会太深入的讲解, 在您看完本系列之后, 能基本甚至熟练的使用.Net Core进行Web开发, 感受到.Net Core的魅力. 本教程知识点大体 ...

  10. spring 对jdbc的简化

    spring.xml <!-- 加载属性配置文件 --> <util:properties id="db" location="classpath:db ...