对webmagic总体构架的理解与代码分析——Spider篇

Spring boot+webMagic实现自动化爬取网站内容 本文摘自:https://funyan.cn/p/6861.html 前言 在网站中,内容才是王道,如果你的网站功能很多也很好看,但是没有内容,那么将毫无意义,但是要是靠站长自己写的话那将是一段非常漫长的过程,所以这时候就需要借鉴其他站的内容,来丰富自己的网站,所以爬虫就出现了,那么今天就教大家如何使用Spring boot+webMagic实现自动化爬取网站内。 开发过程 第一步:引入webMagic <dependency> <groupId. 阅读详情

不得不说webmagic是一个很优秀的爬虫框架,但是我要怎么做才能吃透它呢?我是爬虫初学者,我接下来要做的是将webmagic的代码梳理一遍,不知道我能不能将其整理好,并且灵活运用,举一反三呢。在这个过程中会遇到很多别的知识点,我会另外写博文,来总结其他我不会的东西,现在我要做的就是先分析webmagic的代码。(我自己的理解与分析会用黑色字体,而webmagic框架,黄亿华老师的东西,我会用其他颜色来标注上)

WebMagic的结构分为Downloader、PageProcessor、Scheduler、Pipeline四大组件,并由Spider将它们彼此组织起来。这四大组件对应爬虫生命周期中的下载、处理、管理和持久化等功能。WebMagic的设计参考了Scapy,但是实现方式更Java化一些。

既然webmagic的组件由Spider组织起来,那么我就直接从Spider入手吧。由于代码太多了,在这里面复制出来太多了,http://webmagic.io/  这是webmagic的连接,里面什么都有


控制爬虫运转的引擎Spider类:

Spider类给我的感觉是webmagic框架的大集合,将webmagic框架里面所有有用的东西都整合到这一个类里面了,所以黄亿华老师在文档中才会说到WebMagic的结构分为Downloader、PageProcessor、Scheduler、Pipeline四大组件,并由Spider将它们彼此组织起来。这四大组件对应爬虫生命周期中的下载、处理、管理和持久化等功能。而Spider则将这几个组件组织起来,让它们可以互相交互,流程化的执行,可以认为Spider是一个大的容器,它也是WebMagic逻辑的核心。即,webmagic的入口就是Spider,要想实现一个爬虫程序,首先从Spider入手,结合下面的例子会更好的理解“Spider是爬虫的入口,它封装了爬虫的创建、启动、停止、多线程等功能。”!

代码1:

public static void main(String[] args) {
    Spider.create(new GithubRepoPageProcessor())                                 //1定义专门的PageProcessor
              
            .addUrl("https://github.com/code4craft")                             //2从https://github.com/code4craft开始抓 
            
            .setScheduler(new RedisScheduler("localhost"))                       //3设置Scheduler,使用Redis来管理URL队列
              
            .addPipeline(
webmagic学习笔记(4)---webmagic总体架构分析 在笔记(2)、笔记(3)里,我们对webmagic的eclipse开发环境进行了配置并完成了第一个小爬虫的编写,以上算是对webmagic进行了一次感性的认识。从本篇博文开始,开始学习webmagic的实现细节。 一下内容是我在使用了webmagic进行一些小爬虫编写的基础上的一些自己的认识,很大一部分受官方的使用手册影响。说白了,就是自己在理解的基础上重新打了一遍。 首先,祭出总体架构图。 阅读详情

相关推荐

WebMagic爬虫实战项目指南

WebMagic 是一个简单易用且功能强大的数据抓取框架,它具备快速开发、易于维护和扩展的优点,深受广大开发者的喜爱。在这一章中,我们将介绍WebMagic的发展历程、设计理念以及其主要特点和优势。此外,还会探讨WebMagic的框架结构,包括其核心模块的简介和各模块之间的协作关系。WebMagic 的设计初衷是为了简化网络爬虫的开发过程,让开发者能够更加专注于数据抽取的逻辑,而不是底层的实现细节。

weixin_35935514的博客 2306

Webmagic Spider简单框架流程图

原文链接:http://blog.youkuaiyun.com/yasukusury/article/details/78735589

Win11 C盘瘦身终极指南:哪些能删/能移/不能碰?附详细目录清单

本文提供了一份详细的Win11 C盘瘦身终极指南,清晰区分了可安全删除、适合迁移以及绝对不能触碰的系统目录。文章不仅列出了具体的文件夹清单与操作建议,还介绍了使用符号链接和Robocopy进行安全迁移的高阶方法,并附带了自动化脚本,帮助用户从根本上解决C盘空间不足的问题,同时确保系统稳定。

weixin_29246195的博客 1546

XILINX偶然加载不成功的问题原因及解决方法

本文为明德扬原创文章,转载请注明出处! 一、项目背景 明德扬(MDY)在2021年承担了多个基于XILINX芯片的研发项目,包括VPX网络透明传输项目(芯片为XC7K325T-2FBG900)、某高端测试仪项目(芯片为XCKU060-FFVA1156)、某网闸设备项目(芯片为XC7Z030-FBG676)等,另外,明德扬自研了基于XC7K325T-2FBG900和基于XC7K410T-2FBG900芯片的核心板,在XILINX研发领域拥有丰富的经验。即使拥有丰富经验和积累,每个新项目我们均...

6036

SAP增强实施-第四代显式和隐式增强技术介绍

概念介绍 SAP第四代增强- Enhancement-Point,分为2种显式增强和隐式增强,显式增强就是手动加入到程序中的Enhancement options,隐式增强就是系统内置的Enhancement options。 第四代增强其实是第三代上的加强,都属于面向对象语言的接口技术的应用,但第四代增强使SAP增强实施更具灵活性,四代增强可以直接在源代码里面写增强了代码了,输入参数也不像 二代...

weixin_40672823的博客 7954

用友U8 API 二次开发:WebService封装7个核心DLL引用与U8Login登录避坑

本文详细介绍了用友U8 API二次开发中的WebService封装与U8Login登录优化实践。通过7个核心DLL的正确引用、U8Login登录机制的深度解析及IIS环境下的特殊处理方案,为开发者提供了一套高可用性的通用解决方案,助力企业实现ERP系统的高效集成与数字化转型。

weixin_42524171的博客 505

Xilinx Vivado vitis IDE launch Failed \ Web installer client Obsolete 怎么办

Xilinx vitis_IDE failed Web installer client Obsolete

weixin_44820962的博客 8644

关于在线excel插件Univer笔记教程

univer在线excel插件确实是够强大,但也存在不少bug,用户用起来是真的很爽,和本地的wps差不多,但真正的开发起来是真的费劲。由于文档提供的信息不足,我们很多功能只能去看他们插件里的源代码,然后一点点测试,一点点尝试研究。此文章可省去五天的研究成本

guiplan 5827

高云FPGA系列教程(8):ARM串口数据接收(中断和轮询方式)

GW1NSR-4C ARM部分共有2个串口外设,都挂载在APB1总线上,最高支持波特率921.6Kbit/s,无奇偶校验位,8位数据位,1位停止位,支持高速测试模式 HSTM(High Speed Test Mode),即每个时钟周期输出1位数据,可以在短时间内传输大量数据。官方手册上没有描述发送和接收缓存FIFO的深度,所以不确定是否支持缓存。

whik1194的博客 1685

Android16 rk3576添加触摸点数上限到40个点

本文介绍了在Android 16系统上实现40点触摸支持的修改方案。相比Android 15,Android 16对API添加有更严格的要求,需要在MotionEvent.java中添加@FlaggedApi批注。主要修改包括:1)在input_framework.aconfig中定义flag;2)在MotionEvent.java中添加40个AXIS_GENERIC轴常量并添加批注;3)将32位指针ID处理改为64位适配;4)更新相关API文档。修改涉及多个核心文件,包括PointerController

tzj1058756809的博客 382

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

上一篇: 对java接口和抽象类的理解与区别
下一篇: java中继承Thread和实现Runnable的区别
v7595v
博客等级 码龄12年 18粉丝 45原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值