ruby 爬虫 Spidr 用法

百度搜索引擎爬虫实战:Ruby实现 本文还有配套的精品资源,点击获取 简介:本项目涉及使用Ruby编程语言开发一个百度搜索引擎爬虫,通过自动化手段抓取和分析百度搜索结果。该项目的实现将涵盖网络请求发送、HTML内容解析、正则表达式使用、异步/并发处理、数据存储、延迟与速率控制、异常处理、爬虫框架应用、搜索引擎工作原理理解以及SEO分析等多个方面,旨在深入学习Ruby编程和搜索引擎机制。 1. Rub... 阅读详情

Spidr 是一个Ruby 的网页爬虫库,可以将整个网站、多个网站、某个链接完全抓取到本地。


安装方法:sudo gem install spidr

  • 从一个网址开始爬
      Spidr.start_at('http://tenderlovemaking.com/')
    
  • 爬一个host:
      Spidr.host('coderrr.wordpress.com')
    
  • 爬一个网站:
      Spidr.site('http://rubyflow.com/')
    
  • 多个 hosts:
      Spidr.start_at(
        'http://company.com/',
        :hosts => [
          'company.com',
          /host\d\.company\.com/
        ]
      )
    
  • 忽略某个地址:
      Spidr.site('http://matasano.com/', :ignore_links => [/log/])
    
  • 忽略端口:
      Spidr.site(
        'http://sketchy.content.com/',
        :ignore_ports => [8000, 8010, 8080]
      )
    
  • 打印出爬到的网址:
      Spidr.site('http://rubyinside.org/') do |spider|
        spider.every_url { |url| puts url }
      end
    
  • 打印出失败的网址:
      Spidr.site('http://sketchy.content.com/') do |spider|
        spider.every_failed_url { |url| puts url }
      end
    
  • 搜索 HTML 或 XML 页面:
      Spidr.site('http://company.withablog.com/') do |spider|
        spider.every_page do |page|
          puts "[-] #{page.url}"
    
          page.search('//meta').each do |meta|
            name = (meta.attributes['name'] || meta.attributes['http-equiv'])
            value = meta.attributes['content']
    
            puts "    #{name} = #{value}"
          end
        end
      end
    
  • 打印出每个页面的title:
      Spidr.site('http://www.rubypulse.com/') do |spider|
        spider.every_html_page do |page|
          puts page.title
        end
      end
    
  • F访问表头来获取网站用的那种web servers:
      servers = Set[]
    
      Spidr.host('generic.company.com') do |spider|
        spider.all_headers do |headers|
          servers << headers['server']
        end
      end
    
  • 在被禁止的页面停止spider:
      spider = Spidr.host('overnight.startup.com') do |spider|
        spider.every_forbidden_page do |page|
          spider.pause!
        end
      end
    
  • 跳过处理一些页面:
      Spidr.host('sketchy.content.com') do |spider|
        spider.every_missing_page do |page|
          spider.skip_page!
        end
      end
    
  • 跳过处理一些链接:
      Spidr.host('sketchy.content.com') do |spider|
        spider.every_url do |url|
          if url.path.split('/').find { |dir| dir.to_i > 1000 }
            spider.skip_link!
          end
        end
      end
    


crawler:一个基本的 ruby​​ 网络爬虫 一个非常基本的网络爬虫 给定一个 url,将对所有链接页面(在同一域和方案上)执行广度优先爬网,并构建每个页面所依赖的静态资产列表。 它需要一个完整的 url,带有方案(http 或 https)。 给定一个子域,它不会离开它。 即如果给定developer.google.com它将不会抓取developer.google.com之外的任何页面。 它也不会跟随重定向。 ##要求 能切里 在 2.1.1 MRI 上测试 ##用法: require './crawler.rb' # A scheme (http or https) is required. # The crawler will not leave the subdomain (e.g. www) it is assigned # To see a list of urls as they are being crawle 立即下载

相关推荐

用Ruby写的一个网络爬虫

用Ruby写的一个网络爬虫,用到了正则表达式 和哈希表

Spidr: 快速、强大的网页抓取工具

是一个用于抓取网页的 Ruby 库。它允许您快速地遍历网站,并对页面进行多种操作,如提取元数据、下载文件或检测死链。 ## 功能特性 * 支持 HTTP/HTTPS 协议。 * 可以通过自定义规则过滤 URL。 * 提供了多种回调函数,可以对每个页面进行操作。 * 可以将抓取结果保存到数据库中。 ## 使用场景 您可以使用 Spidr 来实现以下功能: * 网站爬虫:遍历...

gitblog_00001的博客 536

轻巧的Ruby Web爬虫/爬虫,具有优雅的DSL,可从页面提取结构化数据。-Ruby开发

带有优雅DSL的Wombat Web抓取工具,可解析来自网页的结构化数据。 用法:gem install wombat抓取页面:最简单的使用Wombat的方法是调用Wombat.crawl并将其传递给Wombat Web抓取工具以及优雅的DSL,该DSL可以分析网页中的结构化数据。 用法:gem install wombat抓取页面:使用Wombat的最简单方法是调用Wombat.crawl并将其传递给一个块:require'wombat'Wombat.crawl do base_url“ https://www.github.com” path“ / “ headline xpath:” // h1“子标题css:” p.alt-lead“ what_is({css:” .one-fourth h4“},:list)链接确实可以探索xpath:'/ html / body / header / div / div / nav [1] / a [4]'做| e | e.gsub(/ Expl

SPIDR - 完美分割用户故事的五种简单技巧

根据INVEST原则,对用户故事的要求是它必须“足够小”或具有合适的大小。用户故事应该足够小,可以在冲刺中完成6-10个。当然这也取决于开发团队的速度。为了原则上实现这一目标,必须相应地分割大型故事。在下文中,我想向您介绍Mike Cohn的简单快速的SPIDR方法。他总结了五种技术,几乎每个大型用户故事都可以分为几种。 钉鞋 Spik...

weixin_33775572的博客 514

Ruby-Wombat轻量级的RubyWeb爬虫

Wombat - 轻量级的Ruby Web爬虫拥有一个优雅的DSL能够解析网页上的结构化数据

crawler:一个用 Ruby 编写的基于文本的小型地牢爬虫

#爬虫# 一个用 Ruby 编写的基于文本的小型地牢爬虫。 CRawler 被设计为 可扩展。 所有游戏数据均通过 JSON 文件提供,程序仅处理游戏引擎。 轻的。 如果它可以运行 Ruby,它就可以运行 CRawler。 毕竟,甚至没有任何图形! 短的。 如果文档比源代码长,我们就做对了。 自然。 没有“选择选项 1 取走匕首”,CRawler 使用自然语言处理来理解简单的命令,例如“从我的包里取走匕首”。 请参阅以获取更多信息。

rkt Fly引擎终极指南:快速部署轻量级容器运行时的完整教程

在当今容器化技术飞速发展的时代,rkt Fly引擎作为一款轻量级容器运行时,正以其卓越的性能和简单易用的特性受到越来越多开发者的青睐。rkt是一个开源的容器运行时和Kubernetes运行时接口,专门设计用于简化Kubernetes应用程序的部署和管理。本指南将带你深入了解rkt Fly引擎的核心优势,并提供从安装到实际应用的完整部署流程。🚀 ## 什么是rkt Fly引擎? rkt Fly

gitblog_00402的博客 1235

(南京观海微电子)——TCON介绍

TCON又称:逻辑板,控制板,在液晶电视里的作用和CRT中的视放板相当,但有本质的区别,逻辑板不是一个纯粹的信号放大器,它输入是LVDS格式信号,而不是RGB。逻辑板的作用是把数字板送来的LVDS或TTL图像数据信号,时钟信号进行处理移位寄存器存储将图像数据信号,时钟信号转换成屏能够识别的控制信号行列信号RSDS控制屏内的MOSFET管工作而控制液晶分子的扭曲度。目前国内主要的TCON板生产商有视显光电。传统TCON的布局主要分为以下两种:X+C分离式和X+C一体式。

m0_75095200的博客 3834

Ruby学习笔记一:安装Ruby与Ruby的爬虫应用

最近终于空下来了,所以下个Ruby玩玩,安装Ruby很简单,去官网下载一个一键安装包既可,linux下的安装,大家Google下就有很多教程了.对于IDE网上说NetBeans支持得很完美,但是因为本人比较喜欢Eclipse,所以还是跟大家推荐EasyEclipse for Ruby and Rails,当然你可以选择只下RoR的插件而不弄个全新的Eclipse. 以前一直在用Java写爬虫工具抓...

windonly 414

信捷XDH PLC多轴运动控制实战:Ethercat总线下的C语言封装技巧

本文深入探讨了在信捷XDH PLC平台上,如何利用C语言对EtherCAT总线多轴运动控制进行高效封装。通过设计全局数据池、模块化状态机及用户友好接口,将底层复杂的运动控制函数库抽象为清晰、可复用的高级模块,显著提升程序稳定性与可维护性,并分享了关键的实战避坑经验。

weixin_29188043的博客 159

Unity地形优化实战:LOD、合批与HLOD打造流畅开放世界

在计算机图形学与游戏开发中,渲染优化是保障应用流畅运行的核心技术。其基本原理在于通过算法与策略,在视觉保真度与硬件资源消耗之间寻求最佳平衡,旨在提升帧率、降低功耗。这一技术的核心价值在于,它直接决定了大规模场景(如开放世界游戏)在性能受限平台(尤其是移动设备)上的可行性。具体到地形渲染这一关键应用场景,开发者需要综合运用多层次细节(LOD)技术来动态调整模型精度,并通过Draw Call合批(Batching)与GPU实例化(GPU Instancing)来大幅减少CPU到GPU的通信开销。对于超大规模世界

weixin_28077113的博客 332

Ruby爬虫框架终极指南:Spidr和Cobweb的优雅爬取方案

在网络数据采集领域,Ruby凭借其简洁的语法和丰富的库生态,成为开发者构建高效爬虫的理想选择。本文将深入解析两款顶尖Ruby爬虫框架——Spidr和Cobweb的核心特性与应用场景,帮助新手快速掌握优雅的数据爬取方案。 ## 一、Spidr:轻量级网站遍历专家 Spidr作为Ruby生态中备受赞誉的爬虫框架,以其轻量设计和强大的站点遍历能力著称。该框架支持多域名爬取、链接过滤和无限深度遍历,特

gitblog_00388的博客 328

MTK 人工智能生态系统 <一> 简介

Neuropilot

New_Tank的博客 3494

ruby爬虫utf8编码相关

ruby爬虫utf8编码相关 http://www.quarkruby.com/2009/9/22/rails-utf-8-and-html-screen-scrapinghttp://www.rubyrailways.com/data-extraction-for...

103

10. 重磅!Spring AI 1.0 正式发布,Java 开发者的 AI神器!

重磅!Spring AI 1.0 正式发布,Java 开发者的 AI神器! 全网最详细的Spring AI 文章,每章都会提供代码入口,让你更容易得入门和理解Spring AI 相关概念,直接节约你百分之六十的学习成本时间。

gorgor在码农 1065

极智芯 | 解读国产CPU之海光

大家好,我是极智视界,本文分享一下 解读国产CPU之海光。希望我的分享能对你的学习有一点帮助。

极智视界 3317

爬虫 source <转>

Spidr 是一个Ruby 的网页爬虫库,可以将整个网站、多个网站、某个链接完全抓取到本地。 http://opensource.youkuaiyun.com/p/spidr 网页爬虫汇总,值得收藏 http://apps.hi.baidu.com/share/detail/105705 wiki http://wiki.blueidea.com/index.php?title=...

wavee的博客 409

【Flink】FlinkCDC获取mysql数据时间类型差8小时时区解决方案

​ 1、背景: 在我们使用FlinkCDC采集mysql数据的时候,日期类型是我们很常见的类型,但是FlinkCDC读取出来会和数据库的日期时间不一致,情况如下 FlinkCDC获取的数据中create_time字段1694597238000转换为时间戳2023-09-13 17:27:18,而数据库中原始数据如下,并没有到下午5点,这就导致了FlinkCDC读出来的时间和数据库中实际的时间不一致的情况,与数据库对比可以发现,这里的时间戳与数据库时间刚好相差了 8 个小时,在实际生产中这种情况是不

一杯咖啡半杯糖的博客 3854

Ruby方面的Spider让你爬爬爬

[b]hpricot[/b] [url]http://wiki.github.com/why/hpricot[/url] [b]Mechanize[/b] http://[b]spidr[/b].rubyforge.org/ http://[b]spider[/b].rubyforge.org/ http://rubyforge.org/projects/[b]rlucene[/b...

蕲春人的博客 142

YOLOv8改进 | 主干网络 | 在backbone添加Swin-Transformer层【论文必备】

YOLOv8改进,Swin-Transform,YOLOv8添加Swin-Transform

kay_545 2367

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

开源爬虫软件汇总

世界上已经成型的爬虫软件多达上百种,本文对较为知名及常见的开源爬虫软件进行梳理,按开发语言进行汇总,如下表所示。虽然搜索引擎也有爬虫,但本次我汇总的只是爬虫软件,而非大型、复杂的搜索引擎,因为很多兄弟只是想爬取数据,而非运营一个搜索引擎。 开源爬虫汇总表 开发语言 软件名称 软件介绍 许可证 Java ...

aizhouqian5537的博客 157

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

几种PHP实现网页抓取的程序代码

使用Google引擎搜索出这样的文章,不错,怕大家搜索不到,特此重新排版转载出来! 网页抓取就像搜索引擎一个可以去自动抓取其它服务器上的内容了,下面我整理的几个php常用做法,大家一起来看看。 抓取某一个网页中的内容,需要对DOM树进行解析,找到指定节点后,再抓取我们需要的内容,过程有点繁琐。LZ总结了几种常用的、易于实现的网页抓取方式,如果熟悉JQuery选择器,这几种框架会相当简单。

纸上得来终觉浅,绝知此事要躬行 2584

深度学习工具包 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")

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

tamiaode
博客等级 码龄16年 1粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值