存储使用mysql,增量更新东方头条全站新闻的标题 新闻简介 发布时间 新闻的每一页的内容 以及新闻内的所有图片。东方头条网没有反爬虫,新闻除了首页,其余板块的都是请求一个js。抓包就可以看到。

项目文件结构。

这是settings.py

 # -*- coding: utf-8 -*-

 # Scrapy settings for eastday project
#
# For simplicity, this file contains only settings considered important or
# commonly used. You can find more settings consulting the documentation:
#
# http://doc.scrapy.org/en/latest/topics/settings.html
# http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html
# http://scrapy.readthedocs.org/en/latest/topics/spider-middleware.html BOT_NAME = 'eastday' SPIDER_MODULES = ['eastday.spiders']
NEWSPIDER_MODULE = 'eastday.spiders' DUPEFILTER_CLASS = "scrapy_redis.dupefilter.RFPDupeFilter"
SCHEDULER = "scrapy_redis.scheduler.Scheduler"
REDIS_START_URLS_AS_SET=True #shezhi strat_urls键是集合,默认是false是列表
SCHEDULER_PERSIST = True DEPTH_PRIORITY=0
RETRY_TIMES = 20 IMAGES_STORE = 'd:/'
IMAGES_EXPIRES = 90 REDIS_HOST = 'localhost'
REDIS_PORT = 6379
# Crawl responsibly by identifying yourself (and your website) on the user-agent
#USER_AGENT = 'eastday (+http://www.yourdomain.com)' # Obey robots.txt rules
ROBOTSTXT_OBEY = False # Configure maximum concurrent requests performed by Scrapy (default: 16)
CONCURRENT_REQUESTS = 10 # Configure a delay for requests for the same website (default: 0)
# See http://scrapy.readthedocs.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
DOWNLOAD_DELAY = 0
# The download delay setting will honor only one of:
#CONCURRENT_REQUESTS_PER_DOMAIN = 16
#CONCURRENT_REQUESTS_PER_IP = 16 # Disable cookies (enabled by default)
#COOKIES_ENABLED = False # Disable Telnet Console (enabled by default)
#TELNETCONSOLE_ENABLED = False # Override the default request headers:
#DEFAULT_REQUEST_HEADERS = {
# 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
# 'Accept-Language': 'en',
#} # Enable or disable spider middlewares
# See http://scrapy.readthedocs.org/en/latest/topics/spider-middleware.html
#SPIDER_MIDDLEWARES = {
# 'eastday.middlewares.EastdaySpiderMiddleware': 543,
#} # Enable or disable downloader middlewares
# See http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html DOWNLOADER_MIDDLEWARES = {
"eastday.middlewares.UserAgentMiddleware": 401,
#"eastday.middlewares.CookiesMiddleware": 402,
} # Enable or disable extensions
# See http://scrapy.readthedocs.org/en/latest/topics/extensions.html
#EXTENSIONS = {
# 'scrapy.extensions.telnet.TelnetConsole': None,
#} # Configure item pipelines
# See http://scrapy.readthedocs.org/en/latest/topics/item-pipeline.html
ITEM_PIPELINES = {
#'eastday.pipelines.EastdayPipeline': 300,
'eastday.pipelines.MysqlDBPipeline':400,
'eastday.pipelines.DownloadImagesPipeline':200,
#'scrapy_redis.pipelines.RedisPipeline': 400, } # Enable and configure the AutoThrottle extension (disabled by default)
# See http://doc.scrapy.org/en/latest/topics/autothrottle.html
#AUTOTHROTTLE_ENABLED = True
# The initial download delay
#AUTOTHROTTLE_START_DELAY = 5
# The maximum download delay to be set in case of high latencies
#AUTOTHROTTLE_MAX_DELAY = 60
# The average number of requests Scrapy should be sending in parallel to
# each remote server
#AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0
# Enable showing throttling stats for every response received:
#AUTOTHROTTLE_DEBUG = False # Enable and configure HTTP caching (disabled by default)
# See http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
#HTTPCACHE_ENABLED = True
#HTTPCACHE_EXPIRATION_SECS = 0
#HTTPCACHE_DIR = 'httpcache'
#HTTPCACHE_IGNORE_HTTP_CODES = []
#HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage'

setting.py

这是items.py

 # -*- coding: utf-8 -*-

 # Define here the models for your scraped items
#
# See documentation in:
# http://doc.scrapy.org/en/latest/topics/items.html import scrapy class EastdayItem(scrapy.Item):
# define the fields for your item here like:
# name = scrapy.Field()
title=scrapy.Field()
url=scrapy.Field()
tag=scrapy.Field()
article=scrapy.Field()
img_urls=scrapy.Field()
crawled_time=scrapy.Field()
pubdate=scrapy.Field()
origin=scrapy.Field() brief = scrapy.Field()
miniimg = scrapy.Field() pass '''
class GuoneiItem(scrapy.Item):
# define the fields for your item here like:
# name = scrapy.Field()
title=scrapy.Field()
url=scrapy.Field()
tag=scrapy.Field()
article=scrapy.Field()
img_urls=scrapy.Field()
crawled_time=scrapy.Field() brief=scrapy.Field()
miniimg=scrapy.Field() pass
'''

items.py

文件太多啦,不一一贴了,源码文件已打包已上传到博客园,但没找到分享文件链接的地方,如果要源码的可以评论中留言。

这是mysql的存储结果:

东方头条内容也是采集其他网站报刊的,内容还是很丰富,把东方头条的爬下来快可以做一个咨询内容的app了。

文章图片采用的是新闻中图片的连接的源文件名,方便前端开发在页面中展现正确的图片。用来做针对用户的数据挖掘的精准兴趣推荐。

使用scrapy_redis,实时增量更新东方头条网全站新闻的更多相关文章

  1. [置顶]使用scrapy_redis,自动实时增量更新东方头条网全站新闻

    存储使用mysql,增量更新东方头条全站新闻的标题 新闻简介 发布时间 新闻的每一页的内容 以及新闻内的所有图片.项目文件结构. 这是run.py的内容 1 #coding=utf-8 2 from ...

  2. sql 数据库实时增量更新

    ---一下sql可以添加到作业中每秒执行一次   数据过多会消耗性能 --数据表如下,其中字段pid mid time price_type是一个组合主键--pid mid time price pr ...

  3. 一步一步跟我学习lucene(19)---lucene增量更新和NRT(near-real-time)Query近实时查询

    这两天加班,不能兼顾博客的更新.请大家见谅. 有时候我们创建完索引之后,数据源可能有更新的内容.而我们又想像数据库那样能直接体如今查询中.这里就是我们所说的增量索引.对于这种需求我们怎么来实现呢?lu ...

  4. [Solr] (源) Solr与MongoDB集成,实时增量索引

    一. 概述 大量的数据存储在MongoDB上,需要快速搜索出目标内容,于是搭建Solr服务. 另外一点,用Solr索引数据后,可以把数据用在不同的项目当中,直接向Solr服务发送请求,返回xml.js ...

  5. Solr与MongoDB集成,实时增量索引

    Solr与MongoDB集成,实时增量索引 一. 概述 大量的数据存储在MongoDB上,需要快速搜索出目标内容,于是搭建Solr服务. 另外一点,用Solr索引数据后,可以把数据用在不同的项目当中, ...

  6. MySQL数据实时增量同步到Kafka - Flume

    转载自:https://www.cnblogs.com/yucy/p/7845105.html MySQL数据实时增量同步到Kafka - Flume   写在前面的话 需求,将MySQL里的数据实时 ...

  7. android studio增量更新

    一.概述 1.1 概念 增量更新即是通过比较 本机安装版本 和 想要安装版本 间的差异,产生一个差异安装包,不需要从官网下载并安装全量安装包,更不需要将本机已安装的版本下载,而仅仅只是安装此差异安装包 ...

  8. Kettle中通过触发器方式实现数据 增量更新

    在使用Kettle进行数据同步的时候, 共有 1.使用时间戳进行数据增量更新 2.使用数据库日志进行数据增量更新 3.使用触发器+快照表 进行数据增量更新 今天要介绍的是第3中方法. 实验的思路是这样 ...

  9. Android 增量更新

    title: Android NDK之增量更新 1.增量更新使用到的库bsdiff和bzip2 bsdiff库是一个开源的二进制差分工具,通过对比Apk的二进制,从而进行差分包的生成. bsdiff库 ...

随机推荐

  1. 修改npm下载模块的安装位置

    默认安装完node.js后会自己安装npm,通过npm下载全局模块默认安装到C:\Users\user\AppData\Roaming目录下,主要有两个文件夹:npm.npm-cache npm:下载 ...

  2. 每日英语:Is It Possible To Reason About Having A Child?

    How can you decide whether to have a child? It's a complex and profound question -- a philosophical ...

  3. nyoj116 士兵杀敌(二)树状数组 插点问线

    士兵杀敌(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:5 描述 南将军手下有N个士兵,分别编号1到N,这些士兵的杀敌数都是已知的. 小工是南将军手下的军师,南将军经常想知 ...

  4. 文件io之——open/close

    一个进程默认打开三个文件描述符: STDIN_FILENO 0STDOUT_FILENO 1STDERR_FILENO 2 man 2 open可查看详情: open函数可以打开或者创建一个文件: # ...

  5. C/C++/C#/Python日志框架

    俗话说,打得一手好log才是一个优秀的程序员. **打log的目的是为了迅速排错或在有争议时拿出证据证明自己.基于这个目的,log不在多,只要抓住一切对自己有利的信息,就可以了.** 日志框架列表 C ...

  6. Linu 修改maven的setting保护文件

    查找目录 find / -name .m2 -d 查看文件: cat settings.xml 修改文件 vi settings.xml 修改后发现保存会出问题,报错W10: Warning: Cha ...

  7. 【WPF】BusyIndicator做Loading遮罩层

    百度了一下,粗略看了几个国内野人的做法,花了时间看下去感觉不太好用(比如有Loading居然只是作为窗体的一个局部控件的,没法全屏遮罩,那要你有何用?),于是谷歌找轮子去. 好用的轮子:http:// ...

  8. C语言 · 十六进制转八进制

    基础练习 十六进制转八进制   时间限制:1.0s   内存限制:512.0MB        锦囊1: 使用二进制.   问题描述 给定n个十六进制正整数,输出它们对应的八进制数. 输入格式 输入的 ...

  9. htonl()函数学习

    今天在网上看到一篇关于htonl()函数的解释,感觉有道理,贴过来大家一起学习! htonl就是把本机字节顺序转化为网络字节顺序 h---host 本地主机 to 就是to 了 n ---net 网络 ...

  10. 修改 login的串口重定向

     1 在console-telnet 使用vi工具编辑 /etc/inittab 文件  vi /etc/inittab (回车)2 按 i 进入编辑模式:3 将文件中的ttyS0  改为 ttyS3 ...