Scrapy 框架 增量式
增量式:
用来检测网站中数据的更新情况
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule
from redis import Redis
class DianyingSpider(CrawlSpider):
"""
www.4567tv.tv
"""
name = 'dianying'
# allowed_domains = ['https://www.4567tv.tv/index.php/vod/show/id/1/page/388.html']
start_urls = ['https://www.4567tv.tv/index.php/vod/show/id/8/page/1.html']
link = LinkExtractor(allow=r'/index.php/vod/show/id/8/page/\d+\.html')
rules = (
Rule(link, callback='parse_item', follow=True),
)
conn = Redis(host='127.0.0.1', port=6379)
def parse_item(self, response):
li_list = response.xpath('//li[@class="col-md-6 col-sm-4 col-xs-3"]')
for li in li_list:
detail_url = 'https://www.4567tv.tv' + li.xpath('./div/a/@href').extract_first()
if_num = self.conn.sadd('dianying', detail_url)
print(if_num)
if if_num:
print('有最新数据的更新......')
# yield scrapy.Request(url=detail_url, callback=self.detail_callback)
else:
print('暂无最新数据可爬取......')
def detail_callback(self, response):
title = response.xpath('//h1/text()').extract_first()
zhuyan = response.xpath('//div[@class="stui-content__detail"]/p[2]//text()').extract()
print(title, zhuyan)
对于文本内容 使用
import scrapy
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule
from redis import Redis
from qiubaiPro.items import QiubaiproItem
import hashlib
class QiubaiSpider(CrawlSpider):
name = 'qiubai'
# allowed_domains = ['www.xxx.com']
start_urls = ['https://www.******.com/text/']
conn = Redis(host='127.0.0.1',port=6379)
rules = (
Rule(LinkExtractor(allow=r'/text/page/\d+/'), callback='parse_item', follow=True),
)
def parse_item(self, response):
# print(response)
div_list = response.xpath('//div[@id="content-left"]/div')
for div in div_list:
item = QiubaiproItem()
item['author'] = div.xpath('./div[1]/a[2]/h2/text()').extract_first()
item['content'] = div.xpath('.//div[@class="content"]/span//text()').extract()
item['content'] = ''.join(item['content'])
data = item['author']+item['content']
#对数据生成一个数据指纹
data_hash = hashlib.sha256(data.encode()).hexdigest()
ex = self.conn.sadd('if_data',data_hash)
if ex == 1:
print('数据更新,可爬......')
yield item
else:
print('暂无更新数据......')
Scrapy 框架 增量式的更多相关文章
- 基于Scrapy框架的增量式爬虫
概述 概念:监测 核心技术:去重 基于 redis 的一个去重 适合使用增量式的网站: 基于深度爬取的 对爬取过的页面url进行一个记录(记录表) 基于非深度爬取的 记录表:爬取过的数据对应的数据指纹 ...
- Scrapy 增量式爬虫
Scrapy 增量式爬虫 https://blog.csdn.net/mygodit/article/details/83931009 https://blog.csdn.net/mygodit/ar ...
- 爬虫---scrapy分布式和增量式
分布式 概念: 需要搭建一个分布式的机群, 然后在每一台电脑中执行同一组程序, 让其对某一网站的数据进行联合分布爬取. 原生的scrapy框架不能实现分布式的原因 调度器不能被共享, 管道也不能被共享 ...
- 爬虫07 /scrapy图片爬取、中间件、selenium在scrapy中的应用、CrawlSpider、分布式、增量式
爬虫07 /scrapy图片爬取.中间件.selenium在scrapy中的应用.CrawlSpider.分布式.增量式 目录 爬虫07 /scrapy图片爬取.中间件.selenium在scrapy ...
- Scrapy 框架 总结
总结: 1.中间件:下载中间件(拦截请求和响应) - process_request: - prceess_response: - process_exception: - 请求: - UA伪装: - ...
- Scrapy框架(3)
一.如何提升scrapy框架的爬取效率 增加并发: 默认scrapy开启的并发线程为32个,可以适当进行增加.在settings配置文件中修改CONCURRENT_REQUESTS = 100,并发设 ...
- Scrapy框架学习参考资料
00.Python网络爬虫第三弹<爬取get请求的页面数据> 01.jupyter环境安装 02.Python网络爬虫第二弹<http和https协议> 03.Python网络 ...
- Scrapy框架的应用
一, Scrapy Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架,非常出名,非常强悍.所谓的框架就是一个已经被集成了各种功能(高性能异步下载,队列,分布式,解析,持久化等)的具有 ...
- 爬虫Ⅱ:scrapy框架
爬虫Ⅱ:scrapy框架 step5: Scrapy框架初识 Scrapy框架的使用 pySpider 什么是框架: 就是一个具有很强通用性且集成了很多功能的项目模板(可以被应用在各种需求中) scr ...
随机推荐
- Python全栈开发之---输入输出与流程控制
Python简介 python是吉多·范罗苏姆发明的一种面向对象的脚本语言,可能有些人不知道面向对象和脚本具体是什么意思,但是对于一个初学者来说,现在并不需要明白.大家都知道,当下全栈工程师的概念很火 ...
- mapper代理方式开发
使用mapper代理方式开发: 需要编写mapper接口,UserMapper.java需要编写映射文件,UserMapper.xml需要遵循一些开发规范,mybatis便可以自动生成mapper接口 ...
- CSS制作镂空字体
1.效果图 2.html内容: <!doctype html><html lang="en"><head> <meta charset=& ...
- css3 简易时钟
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- phpcms导航菜单的写法
PHP打印方法: {php print_r(变量);} <?php print_r(变量);?> 1. <div class="webnav"> {pc:g ...
- phpcms配置列表页以及获得文章发布时间
<div class="moocConDetail"> {pc:content action="lists" catid="11" ...
- HDU1846 Brave Game
Brave Game Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- BZOJ 1874: [BeiJing2009 WinterCamp]取石子游戏(SG函数)
Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 871 Solved: 365[Submit][Status][Discuss] Description ...
- iTools(pro)下载
http://bbs.feng.com/forum.php?mod=viewthread&tid=10225990&page=1&extra=#pid157941878 htt ...
- JavaScript常用函数
JavaScript常用函数 常规函数 数组函数 日期函数 数学函数 字符串函数 常规函数 (1)alert函数:显示一个警告对话框,包括一个OK按钮.(alert("输入错误") ...